summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/hof/test/repeat.cpp
blob: 19b3b51d7cb0050495cd182dd72a8c7e83900dfa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*=============================================================================
    Copyright (c) 2017 Paul Fultz II
    repeat.cpp
    Distributed under the Boost Software License, Version 1.0. (See accompanying
    file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
==============================================================================*/
#include <boost/hof/repeat.hpp>
#include <limits>
#include "test.hpp"

// TODO: Add tests for multiple parameters

struct increment
{
    template<class T>
    constexpr T operator()(T x) const noexcept
    {
        return x + 1;
    }
};

#if BOOST_HOF_HAS_NOEXCEPT_DEDUCTION
BOOST_HOF_TEST_CASE()
{
    static_assert(noexcept(boost::hof::repeat(std::integral_constant<int, 5>())(increment())(1)), "noexcept repeat");
    static_assert(noexcept(boost::hof::repeat(5)(increment())(1)), "noexcept repeat");
}
#endif

BOOST_HOF_TEST_CASE()
{
    BOOST_HOF_TEST_CHECK(boost::hof::repeat(std::integral_constant<int, 5>())(increment())(1) == 6);
    BOOST_HOF_STATIC_TEST_CHECK(boost::hof::repeat(std::integral_constant<int, 5>())(increment())(1) == 6);
}

BOOST_HOF_TEST_CASE()
{
    BOOST_HOF_TEST_CHECK(boost::hof::repeat(5)(increment())(1) == 6);
    BOOST_HOF_STATIC_TEST_CHECK(boost::hof::repeat(5)(increment())(1) == 6);
}

BOOST_HOF_TEST_CASE()
{
    int i = 5;
    BOOST_HOF_TEST_CHECK(boost::hof::repeat(i)(increment())(1) == 6);
}

BOOST_HOF_TEST_CASE()
{
    static const int i = 5;
    BOOST_HOF_TEST_CHECK(boost::hof::repeat(i)(increment())(1) == 6);
    BOOST_HOF_STATIC_TEST_CHECK(boost::hof::repeat(i)(increment())(1) == 6);
}

// BOOST_HOF_TEST_CASE()
// {
//     BOOST_HOF_TEST_CHECK(boost::hof::repeat(std::numeric_limits<int>::max()/4)(increment())(0) == std::numeric_limits<int>::max()/4);
// }

BOOST_HOF_TEST_CASE()
{
    BOOST_HOF_TEST_CHECK(boost::hof::repeat(BOOST_HOF_RECURSIVE_CONSTEXPR_DEPTH+4)(increment())(0) == BOOST_HOF_RECURSIVE_CONSTEXPR_DEPTH+4);
#if BOOST_HOF_HAS_RELAXED_CONSTEXPR
    BOOST_HOF_STATIC_TEST_CHECK(boost::hof::repeat(BOOST_HOF_RECURSIVE_CONSTEXPR_DEPTH+4)(increment())(0) == BOOST_HOF_RECURSIVE_CONSTEXPR_DEPTH+4);
#endif
}