• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*=============================================================================
2     Copyright (c) 2017 Paul Fultz II
3     partial.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/partial.hpp>
8 #include <boost/hof/limit.hpp>
9 #include "test.hpp"
10 
11 static constexpr boost::hof::static_<boost::hof::partial_adaptor<binary_class> > binary_partial = {};
12 
13 static constexpr boost::hof::static_<boost::hof::partial_adaptor<unary_class> > unary_partial = {};
14 
15 static constexpr boost::hof::static_<boost::hof::partial_adaptor<mutable_class> > mutable_partial = {};
16 
17 static constexpr boost::hof::static_<boost::hof::partial_adaptor<void_class> > void_partial = {};
18 
19 static constexpr boost::hof::static_<boost::hof::partial_adaptor<mono_class> > mono_partial = {};
20 
21 static constexpr boost::hof::static_<boost::hof::partial_adaptor<move_class> > move_partial = {};
22 
23 constexpr boost::hof::partial_adaptor<binary_class> binary_partial_constexpr = {};
24 
25 constexpr boost::hof::partial_adaptor<unary_class> unary_partial_constexpr = {};
26 
27 constexpr boost::hof::partial_adaptor<void_class> void_partial_constexpr = {};
28 
29 constexpr boost::hof::partial_adaptor<mono_class> mono_partial_constexpr = {};
30 
BOOST_HOF_TEST_CASE()31 BOOST_HOF_TEST_CASE()
32 {
33     boost::hof::partial_adaptor<void_class>()(1);
34 
35     void_partial(1);
36     void_partial()(1);
37     BOOST_HOF_TEST_CHECK(3 == binary_partial(1)(2));
38     BOOST_HOF_TEST_CHECK(3 == binary_partial(1, 2));
39     BOOST_HOF_TEST_CHECK(3 == unary_partial()(3));
40     BOOST_HOF_TEST_CHECK(3 == unary_partial(3));
41     BOOST_HOF_TEST_CHECK(3 == mono_partial(2));
42     BOOST_HOF_TEST_CHECK(3 == mono_partial()(2));
43 
44     int i1 = 1;
45     BOOST_HOF_TEST_CHECK(3 == binary_partial(2)(i1));
46     BOOST_HOF_TEST_CHECK(3 == mutable_partial(std::ref(i1))(2));
47     BOOST_HOF_TEST_CHECK(3 == i1);
48     int i2 = 1;
49     BOOST_HOF_TEST_CHECK(3 == mutable_partial(i2, 2));
50     BOOST_HOF_TEST_CHECK(3 == i2);
51 
52 }
53 
BOOST_HOF_TEST_CASE()54 BOOST_HOF_TEST_CASE()
55 {
56     BOOST_HOF_TEST_CHECK(3 == (move_class()(1, 2)));
57     BOOST_HOF_TEST_CHECK(3 == (move_partial(1, 2)));
58     BOOST_HOF_TEST_CHECK(3 == (move_partial(1)(2)));
59     BOOST_HOF_TEST_CHECK(3 == (boost::hof::partial(move_class())(1)(2)));
60     BOOST_HOF_TEST_CHECK(3 == (boost::hof::partial(move_class())(1, 2)));
61 }
62 
BOOST_HOF_TEST_CASE()63 BOOST_HOF_TEST_CASE()
64 {
65     void_partial_constexpr(1);
66     void_partial_constexpr()(1);
67     BOOST_HOF_STATIC_TEST_CHECK(3 == binary_partial_constexpr(1)(2));
68     BOOST_HOF_STATIC_TEST_CHECK(3 == binary_partial_constexpr(1, 2));
69     BOOST_HOF_STATIC_TEST_CHECK(3 == unary_partial_constexpr()(3));
70     BOOST_HOF_STATIC_TEST_CHECK(3 == unary_partial_constexpr(3));
71     BOOST_HOF_STATIC_TEST_CHECK(3 == mono_partial_constexpr(2));
72     BOOST_HOF_STATIC_TEST_CHECK(3 == mono_partial_constexpr()(2));
73 }
74 #if BOOST_HOF_HAS_NOEXCEPT_DEDUCTION
BOOST_HOF_TEST_CASE()75 BOOST_HOF_TEST_CASE()
76 {
77     static_assert(noexcept(boost::hof::partial(binary_class{})(1)(2)), "noexcept partial");
78 }
79 #endif
BOOST_HOF_TEST_CASE()80 BOOST_HOF_TEST_CASE()
81 {
82     auto f = boost::hof::partial(boost::hof::limit_c<2>(binary_class()));
83     static_assert(boost::hof::is_invocable<decltype(f), int>::value, "Passing the limit is not callable");
84     static_assert(boost::hof::is_invocable<decltype(f), int, int>::value, "Passing the limit is not callable");
85     static_assert(!boost::hof::is_invocable<decltype(f), int, int, int>::value, "Passing the limit is not callable");
86     static_assert(!boost::hof::is_invocable<decltype(f), int, int, int, int>::value, "Passing the limit is not callable");
87 
88     auto g = f(0);
89     static_assert(boost::hof::is_invocable<decltype(g), int>::value, "Passing the limit is not callable");
90     static_assert(!boost::hof::is_invocable<decltype(g), int, int>::value, "Passing the limit is not callable");
91     static_assert(!boost::hof::is_invocable<decltype(g), int, int, int>::value, "Passing the limit is not callable");
92     static_assert(!boost::hof::is_invocable<decltype(g), int, int, int, int>::value, "Passing the limit is not callable");
93 }
94 
BOOST_HOF_TEST_CASE()95 BOOST_HOF_TEST_CASE()
96 {
97     auto f = boost::hof::partial(binary_class());
98     static_assert(boost::hof::is_invocable<decltype(f), int>::value, "Passing the limit is not callable");
99     static_assert(boost::hof::is_invocable<decltype(f), int, int>::value, "Passing the limit is not callable");
100     static_assert(boost::hof::is_invocable<decltype(f), int, int, int>::value, "Passing the limit is not callable");
101     static_assert(boost::hof::is_invocable<decltype(f), int, int, int, int>::value, "Passing the limit is not callable");
102 
103     auto g = f(0);
104     static_assert(boost::hof::is_invocable<decltype(g), int>::value, "Passing the limit is not callable");
105     static_assert(boost::hof::is_invocable<decltype(g), int, int>::value, "Passing the limit is not callable");
106     static_assert(boost::hof::is_invocable<decltype(g), int, int, int>::value, "Passing the limit is not callable");
107     static_assert(boost::hof::is_invocable<decltype(g), int, int, int, int>::value, "Passing the limit is not callable");
108 }
109