From 075c2e089a50d6a2f566d0415c62aa9a6e09f765 Mon Sep 17 00:00:00 2001 From: Glen Fernandes Date: Wed, 12 Jan 2022 00:58:22 -0500 Subject: [PATCH] Support identity for boost::result_of pre C++11 --- include/boost/functional/identity.hpp | 20 ++++++++++++++++ test/Jamfile.v2 | 2 ++ test/identity_result_of_rvalue_test.cpp | 31 +++++++++++++++++++++++++ test/identity_result_of_test.cpp | 18 ++++++++++++++ 4 files changed, 71 insertions(+) create mode 100644 test/identity_result_of_rvalue_test.cpp create mode 100644 test/identity_result_of_test.cpp diff --git a/include/boost/functional/identity.hpp b/include/boost/functional/identity.hpp index a4929a9..7021c9b 100644 --- a/include/boost/functional/identity.hpp +++ b/include/boost/functional/identity.hpp @@ -34,6 +34,26 @@ struct identity { return value; } #endif + + template + struct result { }; + + template + struct result { + typedef T& type; + }; + +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) + template + struct result { + typedef T&& type; + }; + + template + struct result { + typedef T&& type; + }; +#endif }; } // boost diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 71de379..8767a0b 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -8,4 +8,6 @@ test-suite functional : [ run function_test.cpp ] [ run identity_test.cpp ] [ run identity_rvalue_test.cpp ] + [ run identity_result_of_test.cpp ] + [ run identity_result_of_rvalue_test.cpp ] ; diff --git a/test/identity_result_of_rvalue_test.cpp b/test/identity_result_of_rvalue_test.cpp new file mode 100644 index 0000000..48eea5c --- /dev/null +++ b/test/identity_result_of_rvalue_test.cpp @@ -0,0 +1,31 @@ +/* +Copyright 2022 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include +#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) +#include +#include +#include + +int main() +{ + BOOST_TEST_TRAIT_SAME(boost::result_of::type, + int&&); + BOOST_TEST_TRAIT_SAME(boost::result_of::type, + int&&); + BOOST_TEST_TRAIT_SAME(boost::result_of::type, + int&&); + BOOST_TEST_TRAIT_SAME(boost::result_of::type, + const int&&); + return boost::report_errors(); +} +#else +int main() +{ + return 0; +} +#endif diff --git a/test/identity_result_of_test.cpp b/test/identity_result_of_test.cpp new file mode 100644 index 0000000..822f522 --- /dev/null +++ b/test/identity_result_of_test.cpp @@ -0,0 +1,18 @@ +/* +Copyright 2022 Glen Joseph Fernandes +(glenjofe@gmail.com) + +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) +*/ +#include +#include +#include + +int main() +{ + BOOST_TEST_TRAIT_SAME(boost::result_of::type, int&); + BOOST_TEST_TRAIT_SAME(boost::result_of::type, + const int&); + return boost::report_errors(); +}