28 #ifndef BSL_RESULT_HPP 29 #define BSL_RESULT_HPP 77 template<
typename T,
typename E = errc_type>
97 if (details::result_type::contains_t == lhs.m_which) {
98 if (details::result_type::contains_t == rhs.m_which) {
110 if (details::result_type::contains_t == rhs.m_which) {
150 : m_which{details::result_type::contains_t},
m_t{t}
174 : m_which{details::result_type::contains_t},
m_t{
bsl::move(t)}
189 template<
typename... ARGS>
193 : m_which{details::result_type::contains_t},
m_t{bsl::forward<ARGS>(args)...}
216 : m_which{details::result_type::contains_e},
m_e{e}
218 bsl::error() << e.message() << bsl::endl;
219 bsl::error() << sloc;
240 : m_which{details::result_type::contains_e},
m_e{
bsl::move(e)}
242 bsl::error() << e.message() << bsl::endl;
243 bsl::error() << sloc;
257 if (details::result_type::contains_t == m_which) {
295 if (details::result_type::contains_t == m_which) {
296 construct_at<T>(&
m_t, o.m_t);
299 construct_at<E>(&
m_e, o.m_e);
333 if (details::result_type::contains_t == m_which) {
334 construct_at<T>(&
m_t, bsl::move(o.m_t));
337 construct_at<E>(&
m_e, bsl::move(o.m_e));
358 private_swap(*
this, tmp);
379 private_swap(*
this, tmp);
399 constexpr
result(O val) noexcept =
delete;
419 [[nodiscard]] constexpr T *
422 if (details::result_type::contains_t == m_which) {
437 [[nodiscard]] constexpr T *
get_if() &&noexcept =
delete;
448 [[nodiscard]] constexpr T
const *
451 if (details::result_type::contains_t == m_which) {
466 [[nodiscard]] constexpr T
const *
get_if() const &&noexcept = delete;
478 [[nodiscard]] constexpr E
479 errc(E const &fallback = E{})
const noexcept
481 if (details::result_type::contains_e == m_which) {
499 [[nodiscard]] constexpr
bool 502 return details::result_type::contains_t == m_which;
516 [[nodiscard]] constexpr
bool 519 return details::result_type::contains_e == m_which;
558 template<
typename T,
typename E>
583 template<
typename T,
typename E>
587 return !(lhs == rhs);
constexpr bool operator!=(result< T, E > const &lhs, result< T, E > const &rhs) noexcept
Returns false if the lhs is equal to the rhs, true otherwise.
Definition: result.hpp:585
::uint8_t uint8
defines an 8bit unsigned integer
Definition: cstdint.hpp:45
If the provided type T is nothrow swappable, provides the member constant value equal to true....
Definition: is_nothrow_swappable.hpp:49
constexpr bool operator==(result< T, E > const &lhs, result< T, E > const &rhs) noexcept
Returns true if the lhs is equal to the rhs, false otherwise.
Definition: result.hpp:560
If the provided type is nothrow move assignable, provides the member constant value equal to true....
Definition: is_nothrow_move_assignable.hpp:49
constexpr result(bsl::in_place_t const &ip, ARGS &&... args) noexcept(is_nothrow_constructible< T, ARGS... >::value)
Constructs a bsl::result that contains T by constructing T in place.
Definition: result.hpp:190
BSL_CONSTEXPR ~result() noexcept(is_nothrow_destructible< T >::value)
Destroyes a previously created bsl::result. Since we require E to be trivially destructible,...
Definition: result.hpp:255
constexpr result(E &&e, sloc_type const &sloc=here()) noexcept
Constructs a bsl::result that contains E, by moving "e".
Definition: result.hpp:237
constexpr bool failure() const noexcept
Returns true if the bsl::result contains E, otherwise, if the bsl::result contains T,...
Definition: result.hpp:517
constexpr void destroy_at(T *const ptr) noexcept(noexcept(ptr->T::~T()))
Calls the destructor of the object pointed to by ptr.
Definition: destroy_at.hpp:52
Provides the ability to return T or E from a function, ensuring that T is only created if an error is...
Definition: result.hpp:78
constexpr T * get_if() &noexcept
Returns a handle to T if this object contains T, otherwise it returns a nullptr.
Definition: result.hpp:420
bsl::in_place, bsl::in_place_type, and bsl::in_place_index are disambiguation tags that can be passed...
Definition: in_place.hpp:45
constexpr result & operator=(result const &o) &noexcept(is_nothrow_copy_constructible< T >::value &&is_nothrow_swappable< T >::value)
copy assignment
Definition: result.hpp:354
constexpr result & operator=(result &&o) &noexcept(is_nothrow_move_constructible< T >::value &&is_nothrow_swappable< T >::value)
move assignment
Definition: result.hpp:375
constexpr enable_if_t< is_movable< T >::value > swap(T &lhs, T &rhs) noexcept(is_nothrow_movable< T >::value)
Swaps the given values.
Definition: swap.hpp:54
This class implements the source_location specification that will eventually be included in C++20....
Definition: source_location.hpp:47
constexpr E errc(E const &fallback=E{}) const noexcept
Returns an error code if this object contains E, otherwise it returns "fallback".
Definition: result.hpp:479
constexpr source_location here(source_location const &sloc=source_location::current()) noexcept
This provides a less verbose version of bsl::source_location::current() to help reduce how large this...
Definition: source_location.hpp:185
E m_e
stores an error code when not storing T
Definition: result.hpp:544
If the provided type is nothrow copy constructible, provides the member constant value equal to true....
Definition: is_nothrow_copy_constructible.hpp:49
If the provided types are the same, provides the member constant value equal to true....
Definition: is_same.hpp:48
constexpr void move(fmt< V > &&val) noexcept=delete
Used to prevent a move of bsl::fmt as it must always be a temporary r-value.
If the provided type is nothrow constructible, provides the member constant value equal to true....
Definition: is_nothrow_constructible.hpp:47
constexpr T const * get_if() const &noexcept
Returns a handle to T if this object contains T, otherwise it returns a nullptr.
Definition: result.hpp:449
constexpr result(result &&o) noexcept(//PRQA S 4285 is_nothrow_move_constructible< T >::value)
move constructor
Definition: result.hpp:329
T type
alias for: T
Definition: result.hpp:127
constexpr bool success() const noexcept
Returns true if the bsl::result contains T, otherwise, if the bsl::result contains an error code,...
Definition: result.hpp:500
constexpr result(result const &o) noexcept(//PRQA S 4285 is_nothrow_copy_constructible< T >::value)
copy constructor
Definition: result.hpp:291
If the provided type is nothrow destructible, provides the member constant value equal to true....
Definition: is_nothrow_destructible.hpp:120
constexpr result(E const &e, sloc_type const &sloc=here()) noexcept
Constructs a bsl::result that contains E, by copying "e".
Definition: result.hpp:213
constexpr result(T &&t) noexcept(//PRQA S 2180//NOLINT is_nothrow_move_constructible< T >::value)
Constructs a bsl::result that contains T, by moving "t".
Definition: result.hpp:172
result_type
Defines what a bsl::result is currently storing. This is defined as a bsl::uint8 to ensure it is as s...
Definition: result.hpp:59
If the provided type is nothrow copy assignable, provides the member constant value equal to true....
Definition: is_nothrow_copy_assignable.hpp:49
T m_t
stores T when not storing an error code
Definition: result.hpp:542
constexpr result(T const &t) noexcept(//PRQA S 2180//NOLINT is_nothrow_copy_constructible< T >::value)
Constructs a bsl::result that contains T, by copying "t".
Definition: result.hpp:148
If the provided type is nothrow move constructible, provides the member constant value equal to true....
Definition: is_nothrow_move_constructible.hpp:48