diff options
| author | Felix Morgner <felix.morgner@gmail.com> | 2018-12-08 10:43:50 +0100 |
|---|---|---|
| committer | Felix Morgner <felix.morgner@gmail.com> | 2018-12-08 10:43:50 +0100 |
| commit | 0c1d1a0f24655c22a373c19aac90a6a225a353e6 (patch) | |
| tree | e65fe3c5f8b80bb59910c81c700eb3ed545848bb /src/expected.hpp | |
| parent | f22d1b76c9a957a679b57ddcb67b33cc73a15de1 (diff) | |
| download | wanda-0c1d1a0f24655c22a373c19aac90a6a225a353e6.tar.xz wanda-0c1d1a0f24655c22a373c19aac90a6a225a353e6.zip | |
wanda: reformat source code
Diffstat (limited to 'src/expected.hpp')
| -rw-r--r-- | src/expected.hpp | 144 |
1 files changed, 82 insertions, 62 deletions
diff --git a/src/expected.hpp b/src/expected.hpp index 8cacefe..4555d92 100644 --- a/src/expected.hpp +++ b/src/expected.hpp @@ -7,10 +7,9 @@ namespace wanda { - -template <typename ErrorType> -struct unexpected -{ + template<typename ErrorType> + struct unexpected + { static_assert(!std::is_same_v<ErrorType, void>, "ErrorType can not be 'void'!"); static_assert(!std::is_array_v<ErrorType>, "ErrorType can not be an array type!"); @@ -27,32 +26,41 @@ struct unexpected /** * @brief Construct a new @p unexpected by direct initializing the error object from @p args */ - template <typename... Args> - constexpr explicit unexpected(std::in_place_t, Args &&... args) : m_error(std::forward<Args>(args)...) {} + template<typename... Args> + constexpr explicit unexpected(std::in_place_t, Args &&... args) + : m_error(std::forward<Args>(args)...) + { + } /** * @brief Construct a new @p unexpected by direct initializing the error object from @p il and @p args */ - template < + template< typename U, typename... Args, std::enable_if_t<std::is_constructible_v<ErrorType, std::initializer_list<U>, Args...>> * = nullptr> - constexpr explicit unexpected(std::in_place_t, std::initializer_list<U> il, Args &&... args) : m_error(il, std::forward<Args>(args)...) {} + constexpr explicit unexpected(std::in_place_t, std::initializer_list<U> il, Args &&... args) + : m_error(il, std::forward<Args>(args)...) + { + } /** * @brief Construct a new @p unexpected by direct initializing the error object from @p error */ - template < + template< typename Err = ErrorType, std::enable_if_t<std::is_constructible_v<ErrorType, Err> && !std::is_same_v<std::remove_cv_t<std::remove_reference_t<Err>>, std::in_place_t> && !std::is_same_v<std::remove_cv_t<std::remove_reference_t<Err>>, unexpected>> * = nullptr> - constexpr explicit unexpected(Err &&error) : m_error(std::forward<Err>(error)) {} + constexpr explicit unexpected(Err && error) + : m_error(std::forward<Err>(error)) + { + } /** * @brief Construct a new @p unexpected by copying the value of another @p unexpected of different error type */ - template < + template< typename Err, std::enable_if_t<!( std::is_constructible_v<ErrorType, Err> && @@ -65,12 +73,15 @@ struct unexpected !std::is_convertible_v<unexpected<Err> const &, ErrorType> && !std::is_convertible_v<unexpected<Err> const, ErrorType>)> * = nullptr, std::enable_if_t<!std::is_convertible_v<Err, ErrorType>> * = nullptr> - constexpr explicit unexpected(unexpected<Err> const &error) : m_error(error.m_error) {} + constexpr explicit unexpected(unexpected<Err> const & error) + : m_error(error.m_error) + { + } /** * @brief Construct a new @p unexpected by copying the value of another @p unexpected of different error type */ - template < + template< typename Err, std::enable_if_t<!( std::is_constructible_v<ErrorType, Err> && @@ -83,12 +94,15 @@ struct unexpected !std::is_convertible_v<unexpected<Err> const &, ErrorType> && !std::is_convertible_v<unexpected<Err> const, ErrorType>)> * = nullptr, std::enable_if_t<std::is_convertible_v<Err, ErrorType>> * = nullptr> - constexpr unexpected(unexpected<Err> const &error) : m_error(error.m_error) {} + constexpr unexpected(unexpected<Err> const & error) + : m_error(error.m_error) + { + } /** * @brief Construct a new @p unexpected by moving the value of another @p unexpected of different error type */ - template < + template< typename Err, std::enable_if_t<!( std::is_constructible_v<ErrorType, Err> && @@ -101,12 +115,15 @@ struct unexpected !std::is_convertible_v<unexpected<Err> const &, ErrorType> && !std::is_convertible_v<unexpected<Err> const, ErrorType>)> * = nullptr, std::enable_if_t<!std::is_convertible_v<Err, ErrorType>> * = nullptr> - constexpr explicit unexpected(unexpected<Err> &&error) : m_error(std::move(error.m_error)) {} + constexpr explicit unexpected(unexpected<Err> && error) + : m_error(std::move(error.m_error)) + { + } /** * @brief Construct a new @p unexpected by moving the value of another @p unexpected of different error type */ - template < + template< typename Err, std::enable_if_t<!( std::is_constructible_v<ErrorType, Err> && @@ -119,109 +136,112 @@ struct unexpected !std::is_convertible_v<unexpected<Err> const &, ErrorType> && !std::is_convertible_v<unexpected<Err> const, ErrorType>)> * = nullptr, std::enable_if_t<std::is_convertible_v<Err, ErrorType>> * = nullptr> - constexpr unexpected(unexpected<Err> &&error) : m_error(std::move(error.m_error)) {} + constexpr unexpected(unexpected<Err> && error) + : m_error(std::move(error.m_error)) + { + } /** * @brief Get the error value contained in this @p unexpected instance */ - constexpr ErrorType const &value() const & + constexpr ErrorType const & value() const & { - return m_error; + return m_error; } /** * @brief Get the error value contained in this @p unexpected instance */ - constexpr ErrorType &value() & + constexpr ErrorType & value() & { - return m_error; + return m_error; } /** * @brief Get the error value contained in this @p unexpected instance */ - constexpr ErrorType &&value() && + constexpr ErrorType && value() && { - return std::move(m_error); + return std::move(m_error); } /** * @brief Get the error value contained in this @p unexpected instance */ - constexpr ErrorType const &&value() const && + constexpr ErrorType const && value() const && { - return std::move(m_error); + return std::move(m_error); } /** * @brief Swap the error value of this @p unexpected instance with the one of @p other */ - void swap(unexpected &other) noexcept(std::is_nothrow_swappable_v<ErrorType>) + void swap(unexpected & other) noexcept(std::is_nothrow_swappable_v<ErrorType>) { - using std::swap; - swap(m_error, other.m_error); + using std::swap; + swap(m_error, other.m_error); } - template <typename ErrorType1, typename ErrorType2> - friend constexpr bool operator==(unexpected<ErrorType1> const &lhs, unexpected<ErrorType2> const &rhs); + template<typename ErrorType1, typename ErrorType2> + friend constexpr bool operator==(unexpected<ErrorType1> const & lhs, unexpected<ErrorType2> const & rhs); - template <typename ErrorType1, typename ErrorType2> - friend constexpr bool operator!=(unexpected<ErrorType1> const &lhs, unexpected<ErrorType2> const &rhs); + template<typename ErrorType1, typename ErrorType2> + friend constexpr bool operator!=(unexpected<ErrorType1> const & lhs, unexpected<ErrorType2> const & rhs); - template < + template< typename Err, std::enable_if_t<std::is_swappable_v<Err>> *> - friend void swap(unexpected<Err> &lhs, unexpected<Err> &rhs); + friend void swap(unexpected<Err> & lhs, unexpected<Err> & rhs); private: ErrorType m_error; -}; + }; -template <typename ErrorType> -unexpected(ErrorType)->unexpected<ErrorType>; + template<typename ErrorType> + unexpected(ErrorType)->unexpected<ErrorType>; -/** + /** * @brief Compare two @p unexpected instances for equality */ -template <typename ErrorType1, typename ErrorType2> -constexpr bool operator==(unexpected<ErrorType1> const &lhs, unexpected<ErrorType2> const &rhs) -{ + template<typename ErrorType1, typename ErrorType2> + constexpr bool operator==(unexpected<ErrorType1> const & lhs, unexpected<ErrorType2> const & rhs) + { return lhs.m_error == rhs.m_error; -} + } -/** + /** * @brief Compare two @p unexpected instances for inequality */ -template <typename ErrorType1, typename ErrorType2> -constexpr bool operator!=(unexpected<ErrorType1> const &lhs, unexpected<ErrorType2> const &rhs) -{ + template<typename ErrorType1, typename ErrorType2> + constexpr bool operator!=(unexpected<ErrorType1> const & lhs, unexpected<ErrorType2> const & rhs) + { return lhs.m_error != rhs.m_error; -} + } -/** + /** * @brief Swap the error values of two @p unexpected instances */ -template < - typename Err, - std::enable_if_t<std::is_swappable_v<Err>> * = nullptr> -void swap(unexpected<Err> &lhs, unexpected<Err> &rhs) -{ + template< + typename Err, + std::enable_if_t<std::is_swappable_v<Err>> * = nullptr> + void swap(unexpected<Err> & lhs, unexpected<Err> & rhs) + { lhs.swap(rhs); -} + } -/** + /** * @brief A tag type for @p unexpected */ -struct unexpect_t -{ + struct unexpect_t + { explicit unexpect_t() = default; -}; + }; -/** + /** * @brief A tap for @p unexpected */ -inline constexpr unexpect_t unexpect{}; + inline constexpr unexpect_t unexpect{}; -} // namespace wanda +} // namespace wanda #endif
\ No newline at end of file |
