limit.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. {
  13. auto f = boost::hof::limit(std::integral_constant<int, 2>())(binary_class());
  14. BOOST_HOF_TEST_CHECK(f(1, 2) == 3);
  15. static_assert(boost::hof::function_param_limit<decltype(f)>::value == 2, "Function limit is 2");
  16. }
  17. BOOST_HOF_TEST_CASE()
  18. {
  19. auto f = boost::hof::limit_c<2>(binary_class());
  20. BOOST_HOF_TEST_CHECK(f(1, 2) == 3);
  21. static_assert(boost::hof::function_param_limit<decltype(f)>::value == 2, "Function limit is 2");
  22. }
  23. BOOST_HOF_TEST_CASE()
  24. {
  25. auto f = boost::hof::limit_c<2>(boost::hof::always(3));
  26. BOOST_HOF_TEST_CHECK(f(1, 2) == 3);
  27. BOOST_HOF_TEST_CHECK(f(1) == 3);
  28. BOOST_HOF_TEST_CHECK(f() == 3);
  29. static_assert(boost::hof::function_param_limit<decltype(f)>::value == 2, "Function limit is 2");
  30. static_assert(boost::hof::is_invocable<decltype(f), int>::value, "Invocable");
  31. static_assert(boost::hof::is_invocable<decltype(f), int, int>::value, "Invocable");
  32. static_assert(!boost::hof::is_invocable<decltype(f), int, int, int>::value, "Not Invocable");
  33. }
  34. BOOST_HOF_TEST_CASE()
  35. {
  36. static_assert(!boost::hof::is_invocable<decltype(boost::hof::limit), int>::value, "Not integral constant");
  37. }
  38. BOOST_HOF_TEST_CASE()
  39. {
  40. static_assert(boost::hof::function_param_limit<decltype(boost::hof::pack())>::value == 0, "Failed limit on pack");
  41. static_assert(boost::hof::function_param_limit<decltype(boost::hof::pack(1))>::value == 1, "Failed limit on pack");
  42. static_assert(boost::hof::function_param_limit<decltype(boost::hof::pack(1, 2))>::value == 2, "Failed limit on pack");
  43. }