• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*=============================================================================
2     Copyright (c) 2017 Paul Fultz II
3     pipable.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/pipable.hpp>
8 #include <boost/hof/static.hpp>
9 #include <boost/hof/limit.hpp>
10 #include "test.hpp"
11 
12 static constexpr boost::hof::static_<boost::hof::pipable_adaptor<binary_class> > binary_pipable = {};
13 
14 static constexpr boost::hof::static_<boost::hof::pipable_adaptor<unary_class> > unary_pipable = {};
15 
16 static constexpr boost::hof::static_<boost::hof::pipable_adaptor<mutable_class> > mutable_pipable = {};
17 
18 static constexpr boost::hof::static_<boost::hof::pipable_adaptor<void_class> > void_pipable = {};
19 
20 static constexpr boost::hof::static_<boost::hof::pipable_adaptor<mono_class> > mono_pipable = {};
21 
22 static constexpr boost::hof::static_<boost::hof::pipable_adaptor<move_class> > move_pipable = {};
23 
24 constexpr boost::hof::pipable_adaptor<void_class> void_pipable_constexpr = {};
25 
26 constexpr boost::hof::pipable_adaptor<binary_class> binary_pipable_constexpr = {};
27 
28 constexpr boost::hof::pipable_adaptor<unary_class> unary_pipable_constexpr = {};
29 
30 #if BOOST_HOF_HAS_NOEXCEPT_DEDUCTION
BOOST_HOF_TEST_CASE()31 BOOST_HOF_TEST_CASE()
32 {
33     static_assert(noexcept(1 | binary_pipable(2)), "noexcept pipable");
34     static_assert(noexcept(binary_pipable(1, 2)), "noexcept pipable");
35 }
36 #endif
37 
BOOST_HOF_TEST_CASE()38 BOOST_HOF_TEST_CASE()
39 {
40     void_pipable(1);
41     1 | void_pipable;
42     BOOST_HOF_TEST_CHECK(3 == (1 | binary_pipable(2)));
43     BOOST_HOF_TEST_CHECK(3 == (binary_pipable(1, 2)));
44     BOOST_HOF_TEST_CHECK(3 == (3 | unary_pipable));
45     BOOST_HOF_TEST_CHECK(3 == (3 | unary_pipable()));
46     BOOST_HOF_TEST_CHECK(3 == (unary_pipable(3)));
47     int i1 = 1;
48     BOOST_HOF_TEST_CHECK(3 == (2 | binary_pipable(i1)));
49     BOOST_HOF_TEST_CHECK(3 == (i1 | mutable_pipable(2)));
50     BOOST_HOF_TEST_CHECK(3 == (i1));
51     int i2 = 1;
52     BOOST_HOF_TEST_CHECK(3 == (mutable_pipable(i2, 2)));
53     BOOST_HOF_TEST_CHECK(3 == (i2));
54     BOOST_HOF_TEST_CHECK(3 == (mono_pipable(2)));
55     BOOST_HOF_TEST_CHECK(3 == (2| mono_pipable));
56 }
57 
BOOST_HOF_TEST_CASE()58 BOOST_HOF_TEST_CASE()
59 {
60     BOOST_HOF_TEST_CHECK(3 == (move_class()(1, 2)));
61     BOOST_HOF_TEST_CHECK(3 == (move_pipable(1, 2)));
62     BOOST_HOF_TEST_CHECK(3 == (1 | move_pipable(2)));
63     BOOST_HOF_TEST_CHECK(3 == (1 | boost::hof::pipable(move_class())(2)));
64     BOOST_HOF_TEST_CHECK(3 == (boost::hof::pipable(move_class())(1, 2)));
65 }
66 
BOOST_HOF_TEST_CASE()67 BOOST_HOF_TEST_CASE()
68 {
69     void_pipable_constexpr(1);
70     1 | void_pipable_constexpr;
71     BOOST_HOF_STATIC_TEST_CHECK(3 == (1 | binary_pipable_constexpr(2)));
72     BOOST_HOF_STATIC_TEST_CHECK(3 == (binary_pipable_constexpr(1, 2)));
73     BOOST_HOF_STATIC_TEST_CHECK(3 == (3 | unary_pipable_constexpr));
74     BOOST_HOF_STATIC_TEST_CHECK(3 == (3 | unary_pipable_constexpr()));
75     BOOST_HOF_STATIC_TEST_CHECK(3 == (unary_pipable_constexpr(3)));
76 }
77 
BOOST_HOF_TEST_CASE()78 BOOST_HOF_TEST_CASE()
79 {
80     BOOST_HOF_TEST_CHECK(3 == boost::hof::limit_c<2>(binary_pipable_constexpr)(1, 2));
81     BOOST_HOF_STATIC_TEST_CHECK(3 == boost::hof::limit_c<2>(binary_pipable_constexpr)(1, 2));
82 }
83 
BOOST_HOF_TEST_CASE()84 BOOST_HOF_TEST_CASE()
85 {
86     auto f = boost::hof::pipable(boost::hof::limit_c<2>(binary_class()));
87     static_assert(boost::hof::is_invocable<decltype(f), int, int>::value, "Passing the limit is not callable");
88     static_assert(!boost::hof::is_invocable<decltype(f), int, int, int>::value, "Passing the limit is not callable");
89     static_assert(!boost::hof::is_invocable<decltype(f), int, int, int, int>::value, "Passing the limit is not callable");
90 }
91