]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/hof/test/lambda.cpp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / libs / hof / test / lambda.cpp
1 /*=============================================================================
2 Copyright (c) 2017 Paul Fultz II
3 lambda.cpp
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 ==============================================================================*/
7 #include <boost/hof/lambda.hpp>
8 #include <boost/hof/first_of.hpp>
9 #include <boost/hof/partial.hpp>
10 #include <boost/hof/infix.hpp>
11 #include <boost/hof/pipable.hpp>
12 #include <memory>
13 #include "test.hpp"
14
15
16 static constexpr auto add_one = BOOST_HOF_STATIC_LAMBDA(int x)
17 {
18 return x + 1;
19 };
20
21 template<class F>
22 struct wrapper : F
23 {
24 BOOST_HOF_INHERIT_CONSTRUCTOR(wrapper, F)
25 };
26
27 template<class T>
28 constexpr wrapper<T> wrap(T x)
29 {
30 return x;
31 }
32
33 BOOST_HOF_TEST_CASE()
34 {
35 BOOST_HOF_TEST_CHECK(3 == add_one(2));
36 }
37
38 BOOST_HOF_TEST_CASE()
39 {
40 constexpr auto add_one_again = add_one;
41 BOOST_HOF_TEST_CHECK(3 == add_one_again(2));
42 }
43
44 BOOST_HOF_TEST_CASE()
45 {
46 constexpr auto add_one_again = wrap(add_one);
47 BOOST_HOF_TEST_CHECK(3 == add_one_again(2));
48 }
49
50 namespace test_static {
51
52 BOOST_HOF_STATIC_LAMBDA_FUNCTION(add_one) = [](int x)
53 {
54 return x + 1;
55 };
56
57 BOOST_HOF_TEST_CASE()
58 {
59 BOOST_HOF_TEST_CHECK(add_one(2) == 3);
60 }
61
62 BOOST_HOF_STATIC_LAMBDA_FUNCTION(sum_partial) = boost::hof::partial([](int x, int y)
63 {
64 return x + y;
65 });
66
67 BOOST_HOF_TEST_CASE()
68 {
69 #ifndef _MSC_VER
70 STATIC_ASSERT_EMPTY(sum_partial);
71 #endif
72 BOOST_HOF_TEST_CHECK(3 == sum_partial(1, 2));
73 BOOST_HOF_TEST_CHECK(3 == sum_partial(1)(2));
74 }
75
76 BOOST_HOF_STATIC_LAMBDA_FUNCTION(add_one_pipable) = boost::hof::pipable([](int x)
77 {
78 return x + 1;
79 });
80
81 BOOST_HOF_TEST_CASE()
82 {
83 #ifndef _MSC_VER
84 STATIC_ASSERT_EMPTY(add_one_pipable);
85 #endif
86 BOOST_HOF_TEST_CHECK(3 == add_one_pipable(2));
87 BOOST_HOF_TEST_CHECK(3 == (2 | add_one_pipable));
88 }
89
90 BOOST_HOF_STATIC_LAMBDA_FUNCTION(sum_infix) = boost::hof::infix([](int x, int y)
91 {
92 return x + y;
93 });
94
95 BOOST_HOF_TEST_CASE()
96 {
97 #ifndef _MSC_VER
98 STATIC_ASSERT_EMPTY(sum_infix);
99 #endif
100 BOOST_HOF_TEST_CHECK(3 == (1 <sum_infix> 2));
101 }
102
103 }