#ifndef BOOST_LEAF_TEST_RES_HPP_INCLUDED #define BOOST_LEAF_TEST_RES_HPP_INCLUDED // Copyright 2018-2022 Emil Dotchevski and Reverge Studios, Inc. // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #include "_test_ec.hpp" template class test_res { enum class variant { value, error }; T value_; E error_; variant which_; public: test_res( T const & value ) noexcept: value_(value), error_(), which_(variant::value) { } test_res( E const & error ) noexcept: value_(), error_(error), which_(variant::error) { } template test_res( Enum e, typename std::enable_if::value, Enum>::type * = nullptr ): value_(), error_(make_error_code(e)), which_(variant::error) { } explicit operator bool() const noexcept { return which_==variant::value; } T const & value() const { BOOST_LEAF_ASSERT(which_==variant::value); return value_; } E const & error() const { BOOST_LEAF_ASSERT(which_==variant::error); return error_; } }; template class test_res { enum class variant { value, error }; E error_; variant which_; public: test_res() noexcept: error_(), which_(variant::value) { } test_res( E const & error ) noexcept: error_(error), which_(variant::error) { } template test_res( Enum e, typename std::enable_if::value, Enum>::type * = nullptr ): error_(make_error_code(e)), which_(variant::error) { } explicit operator bool() const noexcept { return which_==variant::value; } void value() const { BOOST_LEAF_ASSERT(which_==variant::value); } E const & error() const { BOOST_LEAF_ASSERT(which_==variant::error); return error_; } }; namespace boost { namespace leaf { template struct is_result_type; template struct is_result_type>: std::true_type { }; } } #endif