iceoryx2
C++ Language Bindings
Loading...
Searching...
No Matches
iox2::legacy::expected< ValueType, ErrorType > Class Template Reference

Implementation of the C++23 expected class which can contain an error or a success value. More...

#include <expected.hpp>

Public Member Functions

 expected ()=delete
 default ctor is deleted since you have to clearly state if the expected contains a success value or an error value
 
 expected (const expected &) noexcept=default
 the copy constructor calls the copy constructor of the contained success value or the error value - depending on what is stored in the expected
 
 expected (expected &&rhs) noexcept
 the move constructor calls the move constructor of the contained success value or the error value - depending on what is stored in the expected
 
template<typename... Targs>
 expected (in_place_t, Targs &&... args) noexcept
 Creates an expected which is signaling success and perfectly forwards the args to the constructor of ValueType.
 
template<typename... Targs>
 expected (unexpect_t, Targs &&... args) noexcept
 Creates an expected which is signaling an error and perfectly forwards the args to the constructor of ErrorType.
 
 ~expected () noexcept=default
 calls the destructor of the success value or error value - depending on what is stored in the expected
 
expectedoperator= (const expected &) noexcept
 calls the copy assignment operator of the contained success value or the error value - depending on what is stored in the expected
 
expectedoperator= (expected &&rhs) noexcept
 calls the move assignment operator of the contained success value or the error value - depending on what is stored in the expected
 
 expected (const detail::ok< ValueType > &successValue) noexcept
 constructs an expected which is signaling success and uses the value provided by successValue to copy construct its success value
 
 expected (detail::ok< ValueType > &&successValue) noexcept
 constructs an expected which is signaling success and uses the value provided by successValue to move construct its success value
 
 expected (const detail::err< ErrorType > &errorValue) noexcept
 constructs an expected which is signaling an error and stores the error value provided by errorValue
 
 expected (detail::err< ErrorType > &&errorValue) noexcept
 constructs an expected which is signaling an error and stores the error value provided by errorValue
 
 operator bool () const noexcept
 returns true if the expected contains a value type and false if it is an error type
 
bool has_value () const noexcept
 returns true if the expected contains a value type and false if it is an error type
 
bool has_error () const noexcept
 returns true if the expected contains an error otherwise false
 
ErrorTypeerror (bb::detail::SourceLocation location=bb::detail::SourceLocation::current()) &noexcept
 returns a lvalue reference to the contained error value, if the expected does not contain an error the error handler is called
 
const ErrorTypeerror (bb::detail::SourceLocation location=bb::detail::SourceLocation::current()) const &noexcept
 returns a const lvalue reference to the contained error value, if the expected does not contain an error the error handler is called
 
ErrorType && error (bb::detail::SourceLocation location=bb::detail::SourceLocation::current()) &&noexcept
 returns a rvalue reference to the contained error value, if the expected does not contain an error the error handler is called
 
const ErrorType && error (bb::detail::SourceLocation location=bb::detail::SourceLocation::current()) const &&noexcept
 returns a const rvalue reference to the contained error value, if the expected does not contain an error the error handler is called
 
template<typename U = ValueType>
enable_if_non_void_t< U > & value (bb::detail::SourceLocation location=bb::detail::SourceLocation::current()) &noexcept
 returns a lvalue reference to the contained success value, if the expected does not contain a success value the error handler is called
 
template<typename U = ValueType>
const enable_if_non_void_t< U > & value (bb::detail::SourceLocation location=bb::detail::SourceLocation::current()) const &noexcept
 returns a const lvalue reference to the contained success value, if the expected does not contain a success value the error handler is called
 
template<typename U = ValueType>
enable_if_non_void_t< U > && value (bb::detail::SourceLocation location=bb::detail::SourceLocation::current()) &&noexcept
 returns a rvalue reference to the contained success value, if the expected does not contain a success value the error handler is called
 
template<typename U = ValueType>
const enable_if_non_void_t< U > && value (bb::detail::SourceLocation location=bb::detail::SourceLocation::current()) const &&noexcept
 returns a const rvalue reference to the contained success value, if the expected does not contain a success value the error handler is called
 
template<typename U = ValueType>
enable_if_non_void_t< U > & operator* () noexcept
 dereferencing operator which returns a reference to the contained success value. if the expected contains an error the error handler is called
 
template<typename U = ValueType>
const enable_if_non_void_t< U > & operator* () const noexcept
 dereferencing operator which returns a reference to the contained success value. if the expected contains an error the error handler is called
 
template<typename U = ValueType>
enable_if_non_void_t< U > * operator-> () noexcept
 arrow operator which returns the pointer to the contained success value if the expected contains an error the error handler is called
 
template<typename U = ValueType>
const enable_if_non_void_t< U > * operator-> () const noexcept
 arrow operator which returns the pointer to the contained success value if the expected contains an error the the error handler is called
 
 operator expected< void, ErrorType > () const noexcept
 conversion operator to a 'void' value type expected which can be useful if you would like to return only the success of a function
 

Friends

template<typename T , typename E >
constexpr bool::iox2::legacy::operator== (const expected< T, E > &, const expected< T, E > &) noexcept
 

Detailed Description

template<typename ValueType, typename ErrorType>
class iox2::legacy::expected< ValueType, ErrorType >

Implementation of the C++23 expected class which can contain an error or a success value.

Parameters
ValueTypetype of the value which can be stored in the expected
ErrorTypetype of the error which can be stored in the expected

Definition at line 150 of file expected.hpp.

Constructor & Destructor Documentation

◆ expected() [1/9]

template<typename ValueType , typename ErrorType >
iox2::legacy::expected< ValueType, ErrorType >::expected ( )
delete

default ctor is deleted since you have to clearly state if the expected contains a success value or an error value

◆ expected() [2/9]

template<typename ValueType , typename ErrorType >
iox2::legacy::expected< ValueType, ErrorType >::expected ( const expected< ValueType, ErrorType > &  )
defaultnoexcept

the copy constructor calls the copy constructor of the contained success value or the error value - depending on what is stored in the expected

◆ expected() [3/9]

template<typename ValueType , typename ErrorType >
iox2::legacy::expected< ValueType, ErrorType >::expected ( expected< ValueType, ErrorType > &&  rhs)
noexcept

the move constructor calls the move constructor of the contained success value or the error value - depending on what is stored in the expected

Note
The move c'tor does not explicitly invalidate the moved-from object but relies on the move c'tor of ValueType or ErrorType to correctly invalidate the stored object

◆ expected() [4/9]

template<typename ValueType , typename ErrorType >
template<typename... Targs>
iox2::legacy::expected< ValueType, ErrorType >::expected ( in_place_t  ,
Targs &&...  args 
)
explicitnoexcept

Creates an expected which is signaling success and perfectly forwards the args to the constructor of ValueType.

Template Parameters
Targsis the template parameter pack for the perfectly forwarded arguments
Parameters
[in]in_place_tcompile time variable to distinguish between constructors with certain behavior
[in]args...arguments which will be forwarded to the 'ValueType' constructor

◆ expected() [5/9]

template<typename ValueType , typename ErrorType >
template<typename... Targs>
iox2::legacy::expected< ValueType, ErrorType >::expected ( unexpect_t  ,
Targs &&...  args 
)
explicitnoexcept

Creates an expected which is signaling an error and perfectly forwards the args to the constructor of ErrorType.

Template Parameters
Targsis the template parameter pack for the perfectly forwarded arguments
Parameters
[in]unexpect_tcompile time variable to distinguish between constructors with certain behavior
[in]args...arguments which will be forwarded to the 'ErrorType' constructor

◆ ~expected()

template<typename ValueType , typename ErrorType >
iox2::legacy::expected< ValueType, ErrorType >::~expected ( )
defaultnoexcept

calls the destructor of the success value or error value - depending on what is stored in the expected

◆ expected() [6/9]

template<typename ValueType , typename ErrorType >
iox2::legacy::expected< ValueType, ErrorType >::expected ( const detail::ok< ValueType > &  successValue)
noexcept

constructs an expected which is signaling success and uses the value provided by successValue to copy construct its success value

Parameters
[in]successValuevalue which will be stored in the expected

◆ expected() [7/9]

template<typename ValueType , typename ErrorType >
iox2::legacy::expected< ValueType, ErrorType >::expected ( detail::ok< ValueType > &&  successValue)
noexcept

constructs an expected which is signaling success and uses the value provided by successValue to move construct its success value

Parameters
[in]successValuevalue which will be moved into the expected

◆ expected() [8/9]

template<typename ValueType , typename ErrorType >
iox2::legacy::expected< ValueType, ErrorType >::expected ( const detail::err< ErrorType > &  errorValue)
noexcept

constructs an expected which is signaling an error and stores the error value provided by errorValue

Parameters
[in]errorValueerror value which will be stored in the expected

◆ expected() [9/9]

template<typename ValueType , typename ErrorType >
iox2::legacy::expected< ValueType, ErrorType >::expected ( detail::err< ErrorType > &&  errorValue)
noexcept

constructs an expected which is signaling an error and stores the error value provided by errorValue

Parameters
[in]errorValueerror value which will be moved into the expected

Member Function Documentation

◆ error() [1/4]

template<typename ValueType , typename ErrorType >
ErrorType && iox2::legacy::expected< ValueType, ErrorType >::error ( bb::detail::SourceLocation  location = bb::detail::SourceLocation::current()) &&
noexcept

returns a rvalue reference to the contained error value, if the expected does not contain an error the error handler is called

Returns
rvalue reference to the internally contained error

◆ error() [2/4]

template<typename ValueType , typename ErrorType >
ErrorType & iox2::legacy::expected< ValueType, ErrorType >::error ( bb::detail::SourceLocation  location = bb::detail::SourceLocation::current()) &
noexcept

returns a lvalue reference to the contained error value, if the expected does not contain an error the error handler is called

Returns
lvalue reference to the internally contained error

Referenced by iox2::bb::stl::Expected< T, E >::error(), and iox2::bb::stl::Expected< T, E >::error().

◆ error() [3/4]

template<typename ValueType , typename ErrorType >
const ErrorType && iox2::legacy::expected< ValueType, ErrorType >::error ( bb::detail::SourceLocation  location = bb::detail::SourceLocation::current()) const &&
noexcept

returns a const rvalue reference to the contained error value, if the expected does not contain an error the error handler is called

Returns
const rvalue reference to the internally contained error

◆ error() [4/4]

template<typename ValueType , typename ErrorType >
const ErrorType & iox2::legacy::expected< ValueType, ErrorType >::error ( bb::detail::SourceLocation  location = bb::detail::SourceLocation::current()) const &
noexcept

returns a const lvalue reference to the contained error value, if the expected does not contain an error the error handler is called

Returns
const lvalue reference to the internally contained error

◆ has_error()

template<typename ValueType , typename ErrorType >
bool iox2::legacy::expected< ValueType, ErrorType >::has_error ( ) const
noexcept

returns true if the expected contains an error otherwise false

Returns
bool which contains true if the expected contains an error

◆ has_value()

template<typename ValueType , typename ErrorType >
bool iox2::legacy::expected< ValueType, ErrorType >::has_value ( ) const
noexcept

returns true if the expected contains a value type and false if it is an error type

Returns
bool which contains true if the expected contains a value type and false if it is an error type

Referenced by iox2::bb::stl::Expected< T, E >::has_value().

◆ operator bool()

template<typename ValueType , typename ErrorType >
iox2::legacy::expected< ValueType, ErrorType >::operator bool ( ) const
explicitnoexcept

returns true if the expected contains a value type and false if it is an error type

Returns
bool which contains true if the expected contains a value type and false if it is an error type

◆ operator expected< void, ErrorType >()

template<typename ValueType , typename ErrorType >
iox2::legacy::expected< ValueType, ErrorType >::operator expected< void, ErrorType > ( ) const
noexcept

conversion operator to a 'void' value type expected which can be useful if you would like to return only the success of a function

Returns
converts an expected which can contain a value and an error to an expected which contains only an error
}
Implementation of the C++23 expected class which can contain an error or a success value.
Definition expected.hpp:150
constexpr bool always_false_v
Helper value to bind a static_assert to a type.

◆ operator*() [1/2]

template<typename ValueType , typename ErrorType >
template<typename U = ValueType>
const enable_if_non_void_t< U > & iox2::legacy::expected< ValueType, ErrorType >::operator* ( ) const
noexcept

dereferencing operator which returns a reference to the contained success value. if the expected contains an error the error handler is called

Template Parameters
Uhelper template parameter for SFINEA
Returns
const reference to the contained value
Note
this only works for non void ValueTypes
*frodo += 12;
IOX2_LOG(Info, *frodo); // prints 57
#define IOX2_LOG(level, msg_stream)
Macro for logging.
Definition logging.hpp:63
detail::ok< void > ok()
convenience function to create an 'expected' with a 'void' value type

◆ operator*() [2/2]

template<typename ValueType , typename ErrorType >
template<typename U = ValueType>
enable_if_non_void_t< U > & iox2::legacy::expected< ValueType, ErrorType >::operator* ( )
noexcept

dereferencing operator which returns a reference to the contained success value. if the expected contains an error the error handler is called

Template Parameters
Uhelper template parameter for SFINEA
Returns
reference to the contained value
Note
this only works for non void ValueTypes
*frodo += 12;
IOX2_LOG(Info, *frodo); // prints 57

◆ operator->() [1/2]

template<typename ValueType , typename ErrorType >
template<typename U = ValueType>
const enable_if_non_void_t< U > * iox2::legacy::expected< ValueType, ErrorType >::operator-> ( ) const
noexcept

arrow operator which returns the pointer to the contained success value if the expected contains an error the the error handler is called

Template Parameters
Uhelper template parameter for SFINEA
Returns
pointer of type const ValueType to the contained value
Note
this only works for non void ValueTypes
expected<std::vector<int>, int> holyPiotr(ok<std::vector<int>>({1,2,3}));
holyPiotr->push_back(4);

◆ operator->() [2/2]

template<typename ValueType , typename ErrorType >
template<typename U = ValueType>
enable_if_non_void_t< U > * iox2::legacy::expected< ValueType, ErrorType >::operator-> ( )
noexcept

arrow operator which returns the pointer to the contained success value if the expected contains an error the error handler is called

Template Parameters
Uhelper template parameter for SFINEA
Returns
pointer of type ValueType to the contained value
Note
this only works for non void ValueTypes
expected<std::vector<int>, int> holyPiotr(ok<std::vector<int>>({1,2,3}));
holyPiotr->push_back(4);

◆ operator=() [1/2]

template<typename ValueType , typename ErrorType >
expected & iox2::legacy::expected< ValueType, ErrorType >::operator= ( const expected< ValueType, ErrorType > &  )
noexcept

calls the copy assignment operator of the contained success value or the error value - depending on what is stored in the expected

◆ operator=() [2/2]

template<typename ValueType , typename ErrorType >
expected & iox2::legacy::expected< ValueType, ErrorType >::operator= ( expected< ValueType, ErrorType > &&  rhs)
noexcept

calls the move assignment operator of the contained success value or the error value - depending on what is stored in the expected

Note
The move assignment operator does not explicitly invalidate the moved-from object but relies on the move assignment operator of ValueType or ErrorType to correctly invalidate the stored object

◆ value() [1/4]

template<typename ValueType , typename ErrorType >
template<typename U = ValueType>
enable_if_non_void_t< U > && iox2::legacy::expected< ValueType, ErrorType >::value ( bb::detail::SourceLocation  location = bb::detail::SourceLocation::current()) &&
noexcept

returns a rvalue reference to the contained success value, if the expected does not contain a success value the error handler is called

Template Parameters
Uhelper template parameter for SFINEA
Returns
rvalue reference to the internally contained value

◆ value() [2/4]

template<typename ValueType , typename ErrorType >
template<typename U = ValueType>
enable_if_non_void_t< U > & iox2::legacy::expected< ValueType, ErrorType >::value ( bb::detail::SourceLocation  location = bb::detail::SourceLocation::current()) &
noexcept

returns a lvalue reference to the contained success value, if the expected does not contain a success value the error handler is called

Template Parameters
Uhelper template parameter for SFINEA
Returns
lvalue reference to the internally contained value
Note
this only works for non void ValueTypes

Referenced by iox2::bb::stl::Expected< T, E >::value(), and iox2::bb::stl::Expected< T, E >::value().

◆ value() [3/4]

template<typename ValueType , typename ErrorType >
template<typename U = ValueType>
const enable_if_non_void_t< U > && iox2::legacy::expected< ValueType, ErrorType >::value ( bb::detail::SourceLocation  location = bb::detail::SourceLocation::current()) const &&
noexcept

returns a const rvalue reference to the contained success value, if the expected does not contain a success value the error handler is called

Template Parameters
Uhelper template parameter for SFINEA
Returns
const rvalue reference to the internally contained value

◆ value() [4/4]

template<typename ValueType , typename ErrorType >
template<typename U = ValueType>
const enable_if_non_void_t< U > & iox2::legacy::expected< ValueType, ErrorType >::value ( bb::detail::SourceLocation  location = bb::detail::SourceLocation::current()) const &
noexcept

returns a const lvalue reference to the contained success value, if the expected does not contain a success value the error handler is called

Template Parameters
Uhelper template parameter for SFINEA
Returns
const lvalue reference to the internally contained value
Note
this only works for non void ValueTypes

Friends And Related Symbol Documentation

◆ bool::iox2::legacy::operator==

template<typename ValueType , typename ErrorType >
template<typename T , typename E >
constexpr bool::iox2::legacy::operator== ( const expected< T, E > &  ,
const expected< T, E > &   
)
friend

The documentation for this class was generated from the following file: