forked from boostorg/functional
Support identity for boost::result_of pre C++11
This commit is contained in:
@@ -34,6 +34,26 @@ struct identity {
|
|||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
#endif
|
#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
|
} // boost
|
||||||
|
@@ -8,4 +8,6 @@ test-suite functional :
|
|||||||
[ run function_test.cpp ]
|
[ run function_test.cpp ]
|
||||||
[ run identity_test.cpp ]
|
[ run identity_test.cpp ]
|
||||||
[ run identity_rvalue_test.cpp ]
|
[ run identity_rvalue_test.cpp ]
|
||||||
|
[ run identity_result_of_test.cpp ]
|
||||||
|
[ run identity_result_of_rvalue_test.cpp ]
|
||||||
;
|
;
|
||||||
|
31
test/identity_result_of_rvalue_test.cpp
Normal file
31
test/identity_result_of_rvalue_test.cpp
Normal 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
|
18
test/identity_result_of_test.cpp
Normal file
18
test/identity_result_of_test.cpp
Normal 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();
|
||||||
|
}
|
Reference in New Issue
Block a user