| 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/core/identity.hpp> |
| 9 | #include <boost/core/lightweight_test.hpp> |
| 10 | #include <algorithm> |
| 11 | #include <iterator> |
| 12 | #include <string> |
| 13 | #include <vector> |
| 14 | |
| 15 | bool test(std::string&) |
| 16 | { |
| 17 | return true; |
| 18 | } |
| 19 | |
| 20 | bool test(const std::string&) |
| 21 | { |
| 22 | return true; |
| 23 | } |
| 24 | |
| 25 | template<class T> |
| 26 | bool test(T&) |
| 27 | { |
| 28 | return false; |
| 29 | } |
| 30 | |
| 31 | template<class T> |
| 32 | bool test(const T&) |
| 33 | { |
| 34 | return false; |
| 35 | } |
| 36 | |
| 37 | void simple_test() |
| 38 | { |
| 39 | std::string s1("a"); |
| 40 | BOOST_TEST(boost::identity()(s1) == s1); |
| 41 | BOOST_TEST(&boost::identity()(s1) == &s1); |
| 42 | BOOST_TEST(test(boost::identity()(s1))); |
| 43 | const std::string s2("a"); |
| 44 | BOOST_TEST(boost::identity()(s2) == s2); |
| 45 | BOOST_TEST(&boost::identity()(s2) == &s2); |
| 46 | BOOST_TEST(test(boost::identity()(s2))); |
| 47 | } |
| 48 | |
| 49 | void algorithm_test() |
| 50 | { |
| 51 | std::vector<std::string> v1; |
| 52 | v1.push_back(x: std::string("a")); |
| 53 | v1.push_back(x: std::string("b")); |
| 54 | v1.push_back(x: std::string("c")); |
| 55 | std::vector<std::string> v2; |
| 56 | std::transform(first: v1.begin(), last: v1.end(), result: std::back_inserter(x&: v2), |
| 57 | unary_op: boost::identity()); |
| 58 | BOOST_TEST(v2 == v1); |
| 59 | } |
| 60 | |
| 61 | int main() |
| 62 | { |
| 63 | simple_test(); |
| 64 | algorithm_test(); |
| 65 | return boost::report_errors(); |
| 66 | } |
| 67 |
