]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/hof/test/reveal.cpp
1 /*=============================================================================
2 Copyright (c) 2017 Paul Fultz II
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 ==============================================================================*/
8 #include <boost/hof/reveal.hpp>
9 #include <boost/hof/first_of.hpp>
10 #include <boost/hof/static.hpp>
11 #include <boost/hof/lambda.hpp>
12 #include <boost/hof/fix.hpp>
14 namespace reveal_test
{
16 #define CONDITIONAL_FUNCTION(n) \
20 constexpr int operator()(t ## n) const \
26 CONDITIONAL_FUNCTION(1)
27 CONDITIONAL_FUNCTION(2)
28 CONDITIONAL_FUNCTION(3)
30 typedef boost::hof::first_of_adaptor
<f1
, f2
, f3
> f_type
;
31 static constexpr boost::hof::static_
<f_type
> f
= {};
35 BOOST_HOF_TEST_CHECK(boost::hof::reveal(f
)(t1()) == 1);
36 BOOST_HOF_TEST_CHECK(boost::hof::reveal(f
)(t2()) == 2);
37 BOOST_HOF_TEST_CHECK(boost::hof::reveal(f
)(t3()) == 3);
40 static_assert(boost::hof::is_invocable
<boost::hof::reveal_adaptor
<f_type
>, t1
>::value
, "Invocable");
41 static_assert(boost::hof::is_invocable
<boost::hof::reveal_adaptor
<f_type
>, t2
>::value
, "Invocable");
42 static_assert(boost::hof::is_invocable
<boost::hof::reveal_adaptor
<f_type
>, t3
>::value
, "Invocable");
44 static_assert(!boost::hof::is_invocable
<boost::hof::reveal_adaptor
<f_type
>, int>::value
, "Invocable");
45 // boost::hof::reveal(f)(1);
49 static constexpr auto lam
= boost::hof::first_of(
50 BOOST_HOF_STATIC_LAMBDA(t1
)
54 BOOST_HOF_STATIC_LAMBDA(t2
)
58 BOOST_HOF_STATIC_LAMBDA(t3
)
66 STATIC_ASSERT_EMPTY(lam
);
67 STATIC_ASSERT_EMPTY(boost::hof::reveal(lam
));
68 BOOST_HOF_TEST_CHECK(boost::hof::reveal(lam
)(t1()) == 1);
69 BOOST_HOF_TEST_CHECK(boost::hof::reveal(lam
)(t2()) == 2);
70 BOOST_HOF_TEST_CHECK(boost::hof::reveal(lam
)(t3()) == 3);
72 // boost::hof::reveal(lam)(1);
77 BOOST_HOF_STATIC_LAMBDA_FUNCTION(static_fun
) = boost::hof::first_of(
95 STATIC_ASSERT_EMPTY(static_fun
);
96 // STATIC_ASSERT_EMPTY(boost::hof::reveal(static_fun));
98 BOOST_HOF_TEST_CHECK(boost::hof::reveal(static_fun
)(t1()) == 1);
99 BOOST_HOF_TEST_CHECK(boost::hof::reveal(static_fun
)(t2()) == 2);
100 BOOST_HOF_TEST_CHECK(boost::hof::reveal(static_fun
)(t3()) == 3);
102 BOOST_HOF_TEST_CHECK(static_fun(t1()) == 1);
103 BOOST_HOF_TEST_CHECK(static_fun(t2()) == 2);
104 BOOST_HOF_TEST_CHECK(static_fun(t3()) == 3);
106 // boost::hof::reveal(static_fun)(1);
112 BOOST_HOF_USING_TYPENAME(failure_alias
, std::enable_if
<std::is_integral
<T
>::value
>::type
);
115 : boost::hof::as_failure
<failure_alias
>
118 template<class T
, class=typename
std::enable_if
<std::is_integral
<T
>::value
>::type
>
119 constexpr T
operator()(T x
) const
125 struct dont_catch
{};
130 BOOST_HOF_USING_TYPENAME(failure_alias
, std::enable_if
<!std::is_same
<T
, dont_catch
>::value
>::type
);
133 : boost::hof::as_failure
<failure_alias
>
136 template<class T
, class=typename
std::enable_if
<!std::is_same
<T
, dont_catch
>::value
>::type
>
137 constexpr int operator()(T
) const
143 static constexpr boost::hof::reveal_adaptor
<boost::hof::first_of_adaptor
<integral_type
, catch_all
>> check_failure
= {};
146 BOOST_HOF_TEST_CASE()
148 BOOST_HOF_TEST_CHECK(check_failure(5) == 5);
149 BOOST_HOF_TEST_CHECK(check_failure(foo()) == -1);
151 static_assert(!boost::hof::is_invocable
<decltype(check_failure
), dont_catch
>::value
, "Invocable");
152 static_assert(!boost::hof::is_invocable
<decltype(check_failure
), int, int>::value
, "Invocable");
154 // check_failure(dont_catch());