STX  1.0.0
panic_helpers.h
Go to the documentation of this file.
1 
30 #pragma once
31 
32 #include "stx/panic.h"
33 
35 
36 namespace internal {
37 
38 // Forced inline functions basically function like macros.
39 
40 namespace option {
41 
44  std::string_view const& msg,
45  SourceLocation const& location = SourceLocation::current()) noexcept {
46  panic(msg, location);
47 }
48 
51  std::string_view const& msg,
52  SourceLocation const& location = SourceLocation::current()) noexcept {
53  panic(msg, location);
54 }
55 
57 [[noreturn]] STX_FORCE_INLINE void no_value(
58  SourceLocation const& location = SourceLocation::current()) noexcept {
59  panic("called `Option::unwrap()` on a `None` value", location);
60 }
61 
63 [[noreturn]] STX_FORCE_INLINE void no_lref(
64  SourceLocation const& location = SourceLocation::current()) noexcept {
65  panic("called `Option::value()` on a `None` value", location);
66 }
67 
69 [[noreturn]] STX_FORCE_INLINE void no_none(
70  SourceLocation const& location = SourceLocation::current()) noexcept {
71  panic("called `Option::unwrap_none()` on a `Some` value", location);
72 }
73 
74 } // namespace option
75 
76 namespace result {
77 
79 template <typename T>
81  std::string_view const& msg, T const& err,
82  SourceLocation const& location = SourceLocation::current()) noexcept {
83  panic(msg, err, location);
84 }
85 
88  std::string_view const& msg,
89  SourceLocation const& location = SourceLocation::current()) noexcept {
90  panic(msg, location);
91 }
92 
94 template <typename T>
95 [[noreturn]] STX_FORCE_INLINE void no_value(
96  T const& err,
97  SourceLocation const& location = SourceLocation::current()) noexcept {
98  panic("called `Result::unwrap()` on an `Err` value", err, location);
99 }
100 
102 template <typename T>
103 [[noreturn]] STX_FORCE_INLINE void no_lref(
104  T const& err,
105  SourceLocation const& location = SourceLocation::current()) noexcept {
106  panic("called `Result::value()` on an `Err` value", err, location);
107 }
108 
110 [[noreturn]] STX_FORCE_INLINE void no_err(
111  SourceLocation const& location = SourceLocation::current()) noexcept {
112  panic("called `Result::unwrap_err()` on an `Ok` value", location);
113 }
114 
116 [[noreturn]] STX_FORCE_INLINE void no_err_lref(
117  SourceLocation const& location = SourceLocation::current()) noexcept {
118  panic("called `Result::err_value()` on an `Ok` value", location);
119 }
120 
121 } // namespace result
122 } // namespace internal
123 
STX_FORCE_INLINE void no_err(SourceLocation const &location=SourceLocation::current()) noexcept
panic helper for Result<T, E>::unwrap_err() when a value is present
Definition: panic_helpers.h:110
STX_FORCE_INLINE void no_none(SourceLocation const &location=SourceLocation::current()) noexcept
panic helper for Option<T>::unwrap_none() when a value is present
Definition: panic_helpers.h:69
STX_FORCE_INLINE void no_lref(T const &err, SourceLocation const &location=SourceLocation::current()) noexcept
panic helper for Result<T, E>::value() when no value is present
Definition: panic_helpers.h:103
#define STX_FORCE_INLINE
Definition: config.h:254
STX_FORCE_INLINE void expect_value_failed(std::string_view const &msg, T const &err, SourceLocation const &location=SourceLocation::current()) noexcept
panic helper for Result<T, E>::expect() when no value is present
Definition: panic_helpers.h:80
STX_FORCE_INLINE void expect_err_failed(std::string_view const &msg, SourceLocation const &location=SourceLocation::current()) noexcept
panic helper for Result<T, E>::expect_err() when a value is present
Definition: panic_helpers.h:87
STX_FORCE_INLINE void no_err_lref(SourceLocation const &location=SourceLocation::current()) noexcept
panic helper for Result<T, E>::err_value() when no value is present
Definition: panic_helpers.h:116
STX_FORCE_INLINE void expect_none_failed(std::string_view const &msg, SourceLocation const &location=SourceLocation::current()) noexcept
panic helper for Option<T>::expect_none() when a value is present
Definition: panic_helpers.h:50
#define STX_END_NAMESPACE
Definition: config.h:329
Definition: source_location.h:48
STX_FORCE_INLINE void no_value(T const &err, SourceLocation const &location=SourceLocation::current()) noexcept
panic helper for Result<T, E>::unwrap() when no value is present
Definition: panic_helpers.h:95
#define STX_BEGIN_NAMESPACE
Definition: config.h:325
STX_FORCE_INLINE void panic(std::string_view const &info, T const &value, SourceLocation const &location=SourceLocation::current()) noexcept
Definition: panic.h:63