Electroneum
Loading...
Searching...
No Matches
expect.h File Reference
#include <cassert>
#include <system_error>
#include <type_traits>
#include <utility>
#include "common/error.h"
Include dependency graph for expect.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  detail::expect
class  expect< T >
class  expect< void >

Namespaces

namespace  detail
 declaration and default definition for the functions used the API

Macros

#define ELECTRONEUM_PRECOND(...)
 If precondition fails, return ::error::kInvalidArgument in current scope.
#define ELECTRONEUM_CHECK(...)
 Check expect<void> and return errors in current scope.
#define ELECTRONEUM_UNWRAP(...)
#define ELECTRONEUM_THROW(code, msg)

Typedefs

template<bool C>
using detail::enable_if = typename std::enable_if<C>::type

Functions

*return An expect< void > object with !has_error ()`. inline expect< void > success() noexcept
template<typename T, typename U>
bool operator== (expect< T > const &lhs, expect< U > const &rhs) noexcept(noexcept(lhs.equal(rhs)))
template<typename T, typename U>
bool operator== (expect< T > const &lhs, U const &rhs) noexcept(noexcept(lhs.equal(rhs)))
template<typename T, typename U>
bool operator== (T const &lhs, expect< U > const &rhs) noexcept(noexcept(rhs.equal(lhs)))
template<typename T, typename U>
bool operator!= (expect< T > const &lhs, expect< U > const &rhs) noexcept(noexcept(lhs.equal(rhs)))
template<typename T, typename U>
bool operator!= (expect< T > const &lhs, U const &rhs) noexcept(noexcept(lhs.equal(rhs)))
template<typename T, typename U>
bool operator!= (T const &lhs, expect< U > const &rhs) noexcept(noexcept(rhs.equal(lhs)))

Macro Definition Documentation

◆ ELECTRONEUM_CHECK

#define ELECTRONEUM_CHECK ( ...)
Value:
do \
{ \
const ::expect<void> result = __VA_ARGS__ ; \
if (!result) \
return result.error(); \
} while (0)

Check expect<void> and return errors in current scope.

Definition at line 47 of file expect.h.

47#define ELECTRONEUM_CHECK(...) \
48 do \
49 { \
50 const ::expect<void> result = __VA_ARGS__ ; \
51 if (!result) \
52 return result.error(); \
53 } while (0)

◆ ELECTRONEUM_PRECOND

#define ELECTRONEUM_PRECOND ( ...)
Value:
do \
{ \
if (!( __VA_ARGS__ )) \
} while (0)
@ kInvalidArgument
A function argument is invalid.
Definition error.h:35

If precondition fails, return ::error::kInvalidArgument in current scope.

Definition at line 39 of file expect.h.

39#define ELECTRONEUM_PRECOND(...) \
40 do \
41 { \
42 if (!( __VA_ARGS__ )) \
43 return {::common_error::kInvalidArgument}; \
44 } while (0)

◆ ELECTRONEUM_THROW

#define ELECTRONEUM_THROW ( code,
msg )
Value:
::detail::expect::throw_( code , msg , __FILE__ , __LINE__ )
static void throw_(std::error_code ec, const char *msg, const char *file, unsigned line)
Definition expect.cpp:64

Definition at line 66 of file expect.h.

66#define ELECTRONEUM_THROW(code, msg) \
67 ::detail::expect::throw_( code , msg , __FILE__ , __LINE__ )

◆ ELECTRONEUM_UNWRAP

#define ELECTRONEUM_UNWRAP ( ...)
Value:
::detail::expect::unwrap( __VA_ARGS__ , nullptr, __FILE__ , __LINE__ )
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:85

Get T from expect<T> by std::move as-if by function call. expect<void> returns nothing.

Exceptions
std::system_errorwith expect<T>::error(), filename and line number when expect<T>::has_error() == true.

Definition at line 60 of file expect.h.

60#define ELECTRONEUM_UNWRAP(...) \
61 ::detail::expect::unwrap( __VA_ARGS__ , nullptr, __FILE__ , __LINE__ )

Function Documentation

◆ !has_error()

*return An expect< void > object with !has_error ( )
noexcept

Definition at line 396 of file expect.h.

397 { return expect<void>{}; }

◆ operator!=() [1/3]

template<typename T, typename U>
bool operator!= ( expect< T > const & lhs,
expect< U > const & rhs )
inlinenoexcept

Definition at line 422 of file expect.h.

423{
424 return !lhs.equal(rhs);
425}
bool equal(expect< U > const &rhs) const noexcept(noexcept(*std::declval< expect< T > >()== *rhs))
Definition expect.h:314

◆ operator!=() [2/3]

template<typename T, typename U>
bool operator!= ( expect< T > const & lhs,
U const & rhs )
inlinenoexcept

Definition at line 429 of file expect.h.

430{
431 return !lhs.equal(rhs);
432}

◆ operator!=() [3/3]

template<typename T, typename U>
bool operator!= ( T const & lhs,
expect< U > const & rhs )
inlinenoexcept

Definition at line 436 of file expect.h.

437{
438 return !rhs.equal(lhs);
439}

◆ operator==() [1/3]

template<typename T, typename U>
bool operator== ( expect< T > const & lhs,
expect< U > const & rhs )
inlinenoexcept

Definition at line 401 of file expect.h.

402{
403 return lhs.equal(rhs);
404}
Here is the caller graph for this function:

◆ operator==() [2/3]

template<typename T, typename U>
bool operator== ( expect< T > const & lhs,
U const & rhs )
inlinenoexcept

Definition at line 408 of file expect.h.

409{
410 return lhs.equal(rhs);
411}

◆ operator==() [3/3]

template<typename T, typename U>
bool operator== ( T const & lhs,
expect< U > const & rhs )
inlinenoexcept

Definition at line 415 of file expect.h.

416{
417 return rhs.equal(lhs);
418}