From 52d7429473371b40b0727c540240ea6bb6ff36d2 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Mon, 26 Sep 2022 21:01:49 +0300 Subject: [PATCH] Add value_type, error_type typedefs to result. Refs #93. --- include/boost/system/result.hpp | 10 ++++++++++ test/CMakeLists.txt | 1 + test/Jamfile.v2 | 1 + test/result_typedefs.cpp | 22 ++++++++++++++++++++++ 4 files changed, 34 insertions(+) create mode 100644 test/result_typedefs.cpp diff --git a/include/boost/system/result.hpp b/include/boost/system/result.hpp index 2e0ddc3..f3d9cbd 100644 --- a/include/boost/system/result.hpp +++ b/include/boost/system/result.hpp @@ -95,6 +95,11 @@ private: variant2::variant v_; +public: + + using value_type = T; + using error_type = E; + public: // constructors @@ -444,6 +449,11 @@ private: variant2::variant v_; +public: + + using value_type = void; + using error_type = E; + public: // constructors diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 55efd27..de8c636 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -149,3 +149,4 @@ boost_test(TYPE run SOURCES result_range_for.cpp) boost_test(TYPE run SOURCES result_value_construct2.cpp) boost_test(TYPE run SOURCES result_error_construct2.cpp) boost_test(TYPE run SOURCES result_convert_construct.cpp) +boost_test(TYPE run SOURCES result_typedefs.cpp) diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index d110d39..ce82929 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -180,3 +180,4 @@ run result_value_construct2.cpp : : : $(CPP11) ; run result_error_construct2.cpp : : : $(CPP11) ; run result_errc_construct.cpp : : : $(CPP11) ; run result_convert_construct.cpp : : : $(CPP11) ; +run result_typedefs.cpp : : : $(CPP11) ; diff --git a/test/result_typedefs.cpp b/test/result_typedefs.cpp new file mode 100644 index 0000000..6a9a63d --- /dev/null +++ b/test/result_typedefs.cpp @@ -0,0 +1,22 @@ +// Copyright 2022 Peter Dimov. +// Distributed under the Boost Software License, Version 1.0. +// https://www.boost.org/LICENSE_1_0.txt + +#include +#include + +using namespace boost::system; + +struct X {}; + +int main() +{ + BOOST_TEST_TRAIT_SAME( result::value_type, int ); + BOOST_TEST_TRAIT_SAME( result::value_type, X ); + BOOST_TEST_TRAIT_SAME( result::value_type, void ); + + BOOST_TEST_TRAIT_SAME( result::error_type, error_code ); + BOOST_TEST_TRAIT_SAME( result::error_type, X ); + + return boost::report_errors(); +}