33 #include <system_error> 34 #include <type_traits> 40 #define MONERO_PRECOND(...) \ 43 if (!( __VA_ARGS__ )) \ 44 return {::common_error::kInvalidArgument}; \ 48 #define MONERO_CHECK(...) \ 51 const ::expect<void> result = __VA_ARGS__ ; \ 53 return result.error(); \ 61 #define MONERO_UNWRAP(...) \ 62 ::detail::expect::unwrap( __VA_ARGS__ , nullptr, __FILE__ , __LINE__ ) 67 #define MONERO_THROW(code, msg) \ 68 ::detail::expect::throw_( code , msg , __FILE__ , __LINE__ ) 82 static void throw_(std::error_code ec,
const char* msg,
const char* file,
unsigned line);
135 static_assert(std::is_nothrow_destructible<T>(),
"T must have a nothrow destructor");
140 return std::is_constructible<T, U>() &&
141 std::is_convertible<U, T>();
152 return *
reinterpret_cast<T*
>(std::addressof(
storage_));
155 T const&
get()
const noexcept
162 void store(U&&
value) noexcept(std::is_nothrow_constructible<T, U>())
165 code_ = std::error_code{};
187 code_ = ::common_error::kInvalidErrorCode;
191 expect(
T val) noexcept(std::is_nothrow_move_constructible<T>())
197 expect(
expect const& src) noexcept(std::is_nothrow_copy_constructible<T>())
205 template<
typename U,
typename = detail::enable_if<is_convertible<U const&>()>>
221 template<
typename U,
typename = detail::enable_if<is_convertible<U>()>>
235 expect&
operator=(
expect const& src) noexcept(std::is_nothrow_copy_constructible<T>() && std::is_nothrow_copy_assignable<T>())
237 if (
this != std::addressof(src))
243 else if (src.has_value())
252 expect&
operator=(
expect&& src) noexcept(std::is_nothrow_move_constructible<T>() && std::is_nothrow_move_assignable<T>())
254 if (
this != std::addressof(src))
260 else if (src.has_value())
318 get() == *rhs :
error() == rhs.error();
322 bool equal(std::error_code
const& rhs)
const noexcept
332 bool equal(U
const& rhs)
const noexcept(noexcept(*std::declval<
expect<T>>() == rhs))
338 bool matches(std::error_condition
const& rhs)
const noexcept
362 code_ = ::common_error::kInvalidErrorCode;
381 return error() == rhs.error();
385 bool equal(std::error_code
const& rhs)
const noexcept
391 bool matches(std::error_condition
const& rhs)
const noexcept
400 template<
typename T,
typename U>
404 return lhs.equal(rhs);
407 template<
typename T,
typename U>
411 return lhs.equal(rhs);
414 template<
typename T,
typename U>
418 return rhs.equal(lhs);
421 template<
typename T,
typename U>
425 return !lhs.equal(rhs);
428 template<
typename T,
typename U>
432 return !lhs.equal(rhs);
435 template<
typename T,
typename U>
439 return !rhs.equal(lhs);
T & value() &
Definition: expect.h:280
bool equal(std::error_code const &rhs) const noexcept
Definition: expect.h:385
expect(expect &&src) noexcept(std::is_nothrow_move_constructible< T >())
Definition: expect.h:213
expect(expect const &src) noexcept(std::is_nothrow_copy_constructible< T >())
Definition: expect.h:197
const uint32_t T[512]
Definition: groestl_tables.h:36
std::error_code code_
Definition: expect.h:347
std::error_code code_
Definition: expect.h:145
bool has_value() const noexcept
Definition: expect.h:274
bool operator!=(expect< T > const &lhs, expect< U > const &rhs) noexcept(noexcept(lhs.equal(rhs)))
Definition: expect.h:423
bool matches(std::error_condition const &rhs) const noexcept
Definition: expect.h:391
T const & value() const &
Definition: expect.h:287
std::aligned_storage< sizeof(T), alignof(T)>::type storage_
Definition: expect.h:146
void maybe_throw() const
Definition: expect.h:168
expect() noexcept
Create a successful object.
Definition: expect.h:354
T * operator->() noexcept
Definition: expect.h:302
int type
Definition: superscalar.cpp:50
expect(expect< U > &&src) noexcept(std::is_nothrow_constructible< T, U >())
Move conversion from U to T.
Definition: expect.h:222
bool equal(U const &rhs) const noexcept(noexcept(*std::declval< expect< T >>()==rhs))
Definition: expect.h:332
std::error_code error_type
Definition: expect.h:351
expect & operator=(expect &&src) noexcept(std::is_nothrow_move_constructible< T >() &&std::is_nothrow_move_assignable< T >())
Definition: expect.h:252
tools::wallet2::message_signature_result_t result
Definition: signature.cpp:62
expect & operator=(expect const &src) noexcept(std::is_nothrow_copy_constructible< T >() &&std::is_nothrow_copy_assignable< T >())
Definition: expect.h:235
bool operator==(expect< T > const &lhs, expect< U > const &rhs) noexcept(noexcept(lhs.equal(rhs)))
Definition: expect.h:402
expect(std::error_code const &code) noexcept
Definition: expect.h:183
bool equal(std::error_code const &rhs) const noexcept
Definition: expect.h:322
void store(U &&value) noexcept(std::is_nothrow_constructible< T, U >())
Definition: expect.h:162
std::error_code error() const noexcept
Definition: expect.h:277
static T unwrap(::expect< T > &&result, const char *error_msg, const char *file, unsigned line)
If result.has_error() call throw_. Otherwise,.
Definition: expect.h:86
T && value() &&
Definition: expect.h:295
expect(expect< U > const &src) noexcept(std::is_nothrow_constructible< T, U const &>())
Copy conversion from U to T.
Definition: expect.h:206
void value_type
Definition: expect.h:350
const portMappingElt code
Definition: portlistingparse.c:22
static constexpr bool is_convertible() noexcept
Definition: expect.h:138
declaration and default definition for the functions used the API
Definition: expect.cpp:33
T value_type
Definition: expect.h:175
bool equal(expect const &rhs) const noexcept
Definition: expect.h:379
expect(std::error_code const &code) noexcept
Definition: expect.h:358
bool matches(std::error_condition const &rhs) const noexcept
Definition: expect.h:338
T & get() noexcept
Definition: expect.h:149
T const * operator->() const noexcept
Definition: expect.h:304
~expect() noexcept
Definition: expect.h:229
bool has_error() const noexcept
Definition: expect.h:373
expect< void > success() noexcept
Definition: expect.h:398
T & operator*() noexcept
Definition: expect.h:306
const T & move(const T &t)
Definition: gtest-port.h:1317
bool equal(expect< U > const &rhs) const noexcept(noexcept(*std::declval< expect< T >>()== *rhs))
Definition: expect.h:315
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1225
static void throw_(std::error_code ec, const char *msg, const char *file, unsigned line)
Definition: expect.cpp:64
int bool
Definition: stdbool.h:35
std::error_code error_type
Definition: expect.h:176
T const & operator*() const noexcept
Definition: expect.h:308
bool has_error() const noexcept
Definition: expect.h:271
typename std::enable_if< C >::type enable_if
Definition: expect.h:77
expect(T val) noexcept(std::is_nothrow_move_constructible< T >())
Store a value, val, in the expect object.
Definition: expect.h:191
line
Definition: check.py:23
#define const
Definition: ipfrdr.c:80
std::error_code error() const noexcept
Definition: expect.h:376