| 1 | /* |
|---|---|
| 2 | Copyright 2021-2023 Glen Joseph Fernandes |
| 3 | (glenjofe@gmail.com) |
| 4 | |
| 5 | Distributed under the Boost Software License, Version 1.0. |
| 6 | (http://www.boost.org/LICENSE_1_0.txt) |
| 7 | */ |
| 8 | #include <boost/config.hpp> |
| 9 | #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) |
| 10 | #include <boost/core/identity.hpp> |
| 11 | #include <boost/core/lightweight_test.hpp> |
| 12 | #include <algorithm> |
| 13 | #include <iterator> |
| 14 | #include <string> |
| 15 | #include <vector> |
| 16 | |
| 17 | bool test(std::string&&) |
| 18 | { |
| 19 | return true; |
| 20 | } |
| 21 | |
| 22 | bool test(const std::string&&) |
| 23 | { |
| 24 | return true; |
| 25 | } |
| 26 | |
| 27 | template<class T> |
| 28 | bool test(T&&) |
| 29 | { |
| 30 | return false; |
| 31 | } |
| 32 | |
| 33 | void simple_test() |
| 34 | { |
| 35 | typedef std::string string; |
| 36 | BOOST_TEST(boost::identity()(string("a")) == string( "a")); |
| 37 | BOOST_TEST(test(boost::identity()(string("a")))); |
| 38 | typedef const std::string cstring; |
| 39 | BOOST_TEST(boost::identity()(cstring("a")) == cstring( "a")); |
| 40 | BOOST_TEST(test(boost::identity()(cstring("a")))); |
| 41 | } |
| 42 | |
| 43 | void algorithm_test() |
| 44 | { |
| 45 | std::vector<std::string> v1; |
| 46 | v1.push_back(x: std::string("a")); |
| 47 | v1.push_back(x: std::string("b")); |
| 48 | v1.push_back(x: std::string("c")); |
| 49 | std::vector<std::string> v2(v1); |
| 50 | std::vector<std::string> v3; |
| 51 | std::transform(first: std::make_move_iterator(i: v2.begin()), |
| 52 | last: std::make_move_iterator(i: v2.end()), |
| 53 | result: std::back_inserter(x&: v3), |
| 54 | unary_op: boost::identity()); |
| 55 | BOOST_TEST(v3 == v1); |
| 56 | } |
| 57 | |
| 58 | int main() |
| 59 | { |
| 60 | simple_test(); |
| 61 | algorithm_test(); |
| 62 | return boost::report_errors(); |
| 63 | } |
| 64 | #else |
| 65 | int main() |
| 66 | { |
| 67 | return 0; |
| 68 | } |
| 69 | #endif |
| 70 |
