| 1 | /*============================================================================= |
|---|---|
| 2 | Copyright (c) 2017 Paul Fultz II |
| 3 | repeat.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/repeat.hpp> |
| 8 | #include <limits> |
| 9 | #include "test.hpp" |
| 10 | |
| 11 | // TODO: Add tests for multiple parameters |
| 12 | |
| 13 | struct increment |
| 14 | { |
| 15 | template<class T> |
| 16 | constexpr T operator()(T x) const noexcept |
| 17 | { |
| 18 | return x + 1; |
| 19 | } |
| 20 | }; |
| 21 | |
| 22 | #if BOOST_HOF_HAS_NOEXCEPT_DEDUCTION |
| 23 | BOOST_HOF_TEST_CASE() |
| 24 | { |
| 25 | static_assert(noexcept(boost::hof::repeat(std::integral_constant<int, 5>())(increment())(1)), "noexcept repeat"); |
| 26 | static_assert(noexcept(boost::hof::repeat(5)(increment())(1)), "noexcept repeat"); |
| 27 | } |
| 28 | #endif |
| 29 | |
| 30 | BOOST_HOF_TEST_CASE() |
| 31 | { |
| 32 | BOOST_HOF_TEST_CHECK(boost::hof::repeat(std::integral_constant<int, 5>())(increment())(1) == 6); |
| 33 | BOOST_HOF_STATIC_TEST_CHECK(boost::hof::repeat(std::integral_constant<int, 5>())(increment())(1) == 6); |
| 34 | } |
| 35 | |
| 36 | BOOST_HOF_TEST_CASE() |
| 37 | { |
| 38 | BOOST_HOF_TEST_CHECK(boost::hof::repeat(5)(increment())(1) == 6); |
| 39 | BOOST_HOF_STATIC_TEST_CHECK(boost::hof::repeat(5)(increment())(1) == 6); |
| 40 | } |
| 41 | |
| 42 | BOOST_HOF_TEST_CASE() |
| 43 | { |
| 44 | int i = 5; |
| 45 | BOOST_HOF_TEST_CHECK(boost::hof::repeat(i)(increment())(1) == 6); |
| 46 | } |
| 47 | |
| 48 | BOOST_HOF_TEST_CASE() |
| 49 | { |
| 50 | static const int i = 5; |
| 51 | BOOST_HOF_TEST_CHECK(boost::hof::repeat(i)(increment())(1) == 6); |
| 52 | BOOST_HOF_STATIC_TEST_CHECK(boost::hof::repeat(i)(increment())(1) == 6); |
| 53 | } |
| 54 | |
| 55 | // BOOST_HOF_TEST_CASE() |
| 56 | // { |
| 57 | // BOOST_HOF_TEST_CHECK(boost::hof::repeat(std::numeric_limits<int>::max()/4)(increment())(0) == std::numeric_limits<int>::max()/4); |
| 58 | // } |
| 59 | |
| 60 | BOOST_HOF_TEST_CASE() |
| 61 | { |
| 62 | BOOST_HOF_TEST_CHECK(boost::hof::repeat(BOOST_HOF_RECURSIVE_CONSTEXPR_DEPTH+4)(increment())(0) == BOOST_HOF_RECURSIVE_CONSTEXPR_DEPTH+4); |
| 63 | #if BOOST_HOF_HAS_RELAXED_CONSTEXPR |
| 64 | BOOST_HOF_STATIC_TEST_CHECK(boost::hof::repeat(BOOST_HOF_RECURSIVE_CONSTEXPR_DEPTH+4)(increment())(0) == BOOST_HOF_RECURSIVE_CONSTEXPR_DEPTH+4); |
| 65 | #endif |
| 66 | } |
| 67 |
