• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*=============================================================================
2     Copyright (c) 2017 Paul Fultz II
3     limit.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/limit.hpp>
8 #include <boost/hof/is_invocable.hpp>
9 #include <boost/hof/pack.hpp>
10 #include "test.hpp"
11 
BOOST_HOF_TEST_CASE()12 BOOST_HOF_TEST_CASE()
13 {
14     auto f = boost::hof::limit(std::integral_constant<int, 2>())(binary_class());
15     BOOST_HOF_TEST_CHECK(f(1, 2) == 3);
16     static_assert(boost::hof::function_param_limit<decltype(f)>::value == 2, "Function limit is 2");
17 }
18 
BOOST_HOF_TEST_CASE()19 BOOST_HOF_TEST_CASE()
20 {
21     auto f = boost::hof::limit_c<2>(binary_class());
22     BOOST_HOF_TEST_CHECK(f(1, 2) == 3);
23     static_assert(boost::hof::function_param_limit<decltype(f)>::value == 2, "Function limit is 2");
24 }
25 
BOOST_HOF_TEST_CASE()26 BOOST_HOF_TEST_CASE()
27 {
28     auto f = boost::hof::limit_c<2>(boost::hof::always(3));
29     BOOST_HOF_TEST_CHECK(f(1, 2) == 3);
30     BOOST_HOF_TEST_CHECK(f(1) == 3);
31     BOOST_HOF_TEST_CHECK(f() == 3);
32     static_assert(boost::hof::function_param_limit<decltype(f)>::value == 2, "Function limit is 2");
33     static_assert(boost::hof::is_invocable<decltype(f), int>::value, "Invocable");
34     static_assert(boost::hof::is_invocable<decltype(f), int, int>::value, "Invocable");
35     static_assert(!boost::hof::is_invocable<decltype(f), int, int, int>::value, "Not Invocable");
36 }
37 
BOOST_HOF_TEST_CASE()38 BOOST_HOF_TEST_CASE()
39 {
40     static_assert(!boost::hof::is_invocable<decltype(boost::hof::limit), int>::value, "Not integral constant");
41 }
42 
BOOST_HOF_TEST_CASE()43 BOOST_HOF_TEST_CASE()
44 {
45     static_assert(boost::hof::function_param_limit<decltype(boost::hof::pack())>::value == 0, "Failed limit on pack");
46     static_assert(boost::hof::function_param_limit<decltype(boost::hof::pack(1))>::value == 1, "Failed limit on pack");
47     static_assert(boost::hof::function_param_limit<decltype(boost::hof::pack(1, 2))>::value == 2, "Failed limit on pack");
48 }
49 
50