Support identity for boost::result_of pre C++11

This commit is contained in:
Glen Fernandes
2022-01-12 00:58:22 -05:00
parent 0be868143d
commit 075c2e089a
4 changed files with 71 additions and 0 deletions

View File

@@ -34,6 +34,26 @@ struct identity {
return value;
}
#endif
template<class>
struct result { };
template<class T>
struct result<identity(T&)> {
typedef T& type;
};
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
template<class T>
struct result<identity(T)> {
typedef T&& type;
};
template<class T>
struct result<identity(T&&)> {
typedef T&& type;
};
#endif
};
} // boost

View File

@@ -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 ]
;

View File

@@ -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 <boost/config.hpp>
#if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
#include <boost/functional/identity.hpp>
#include <boost/core/lightweight_test_trait.hpp>
#include <boost/utility/result_of.hpp>
int main()
{
BOOST_TEST_TRAIT_SAME(boost::result_of<boost::identity(int)>::type,
int&&);
BOOST_TEST_TRAIT_SAME(boost::result_of<boost::identity(const int)>::type,
int&&);
BOOST_TEST_TRAIT_SAME(boost::result_of<boost::identity(int&&)>::type,
int&&);
BOOST_TEST_TRAIT_SAME(boost::result_of<boost::identity(const int&&)>::type,
const int&&);
return boost::report_errors();
}
#else
int main()
{
return 0;
}
#endif

View File

@@ -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 <boost/functional/identity.hpp>
#include <boost/core/lightweight_test_trait.hpp>
#include <boost/utility/result_of.hpp>
int main()
{
BOOST_TEST_TRAIT_SAME(boost::result_of<boost::identity(int&)>::type, int&);
BOOST_TEST_TRAIT_SAME(boost::result_of<boost::identity(const int&)>::type,
const int&);
return boost::report_errors();
}