expected implementation from the C++20 proposal with C++11. The interface is inspired by the proposal but it has changes since we are not allowed to throw an exception.
More...
|
| 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
|
|
| ~expected () noexcept=default |
| calls the destructor of the success value or error value - depending on what is stored in the expected
|
|
expected & | operator= (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
|
|
expected & | operator= (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 success< void > &successValue) noexcept |
| constructs an expected which is signaling success
|
|
| expected (const error< ErrorType > &errorValue) noexcept |
| constructs an expected which is signaling an error and stores the error value provided by errorValue
|
|
| expected (error< ErrorType > &&errorValue) noexcept |
| constructs an expected which is signaling an error and stores the error value provided by value
|
|
| operator bool () const noexcept |
| returns true if the expected contains an error otherwise false
|
|
bool | has_error () const noexcept |
| returns true if the expected contains an error otherwise false
|
|
ErrorType & | get_error () &noexcept |
| returns a reference to the contained error value, if the expected does not contain an error this is undefined behavior
|
|
const ErrorType & | get_error () const &noexcept |
| returns a const reference to the contained error value, if the expected does not contain an error this is undefined behavior
|
|
ErrorType && | get_error () &&noexcept |
| returns a rvalue reference to the contained error value, if the expected does not contain an error this is undefined behavior
|
|
const expected & | or_else (const cxx::function_ref< void(ErrorType &)> &callable) const noexcept |
| if the expected does contain an error the given callable is called and a reference to the ErrorType is given as an argument to the callable
|
|
expected & | or_else (const cxx::function_ref< void(ErrorType &)> &callable) noexcept |
| if the expected does contain an error the given callable is called and a reference to the ErrorType is given as an argument to the callable
|
|
const expected & | and_then (const cxx::function_ref< void()> &callable) const noexcept |
| if the expected does contain a success value the given callable is called and a reference to the expected is given as an argument to the callable
|
|
expected & | and_then (const cxx::function_ref< void()> &callable) noexcept |
| if the expected does contain a success value the given callable is called and a reference to the expected is given as an argument to the callable
|
|
template<typename ErrorType>
class iox::cxx::expected< ErrorType >
expected implementation from the C++20 proposal with C++11. The interface is inspired by the proposal but it has changes since we are not allowed to throw an exception.
- Parameters
-
ErrorType | type of the error which can be stored in the expected |
cxx::expected<int, float> callMe() {
bool l_errorOccured;
if ( l_errorOccured ) {
} else if ( !l_errorOccured ) {
}
}
cxx::expected<float> errorOnlyMethod() {
return callMe().or_else([]{
std::cerr << "Error Occured\n";
}).
and_then([](cxx::expected<int, float> & result){
std::cout << "Success, got " << result.value() << std::endl;
});
}
cxx::expected<std::vector<int>, int> allHailHypnotoad(success<std::vector<int>>({6,6,6}));
allHailHypnotoad->push_back(7);
const expected & and_then(const cxx::function_ref< void()> &callable) const noexcept
if the expected does contain a success value the given callable is called and a reference to the expe...
helper struct to create an expected which is signalling an error more easily
Definition expected.hpp:92
helper struct to create an expected which is signalling success more easily
Definition expected.hpp:49