/* * Copyright 2022-present ScyllaDB */ /* * SPDX-License-Identifier: LicenseRef-ScyllaDB-Source-Available-1.0 */ #pragma once // Basic utilities which allow to start working with boost::outcome::result // in conjunction with our exception_container. #include #include #include #include #include #include "utils/exception_container.hh" namespace bo = BOOST_OUTCOME_V2_NAMESPACE; namespace utils { // A policy which throws the container_error associated with the result // if there was an attempt to access value while it was not present. struct exception_container_throw_policy : bo::policy::base { template static constexpr void wide_value_check(Impl&& self) { if (!base::_has_value(self)) { base::_error(self).throw_me(); } } template static constexpr void wide_error_check(Impl&& self) { if (!base::_has_error(self)) { throw bo::bad_result_access("no error"); } } }; template using result_with_exception = bo::result, exception_container_throw_policy>; template concept ExceptionContainerResult = bo::is_basic_result::value && ExceptionContainer; template concept ExceptionContainerResultFuture = seastar::is_future::value && ExceptionContainerResult; template concept ResultRebindableTo = bo::is_basic_result::value && bo::is_basic_result::value && std::same_as && std::same_as; // Creates a result type which has the same error type as R, but has a different value type. // The name was inspired by std::allocator::rebind. template using rebind_result = bo::result; struct result_with_exception_ptr_throw_policy : bo::policy::base { template static constexpr void wide_value_check(Impl&& self) { if (!base::_has_value(self)) { std::rethrow_exception(base::_error(self)); } } template static constexpr void wide_error_check(Impl&& self) { if (!base::_has_error(self)) { throw bo::bad_result_access("no error"); } } }; template using result_with_exception_ptr = bo::result; template concept ExceptionPtrResult = bo::is_basic_result::value && std::same_as; }