mirror of
https://github.com/boostorg/hof.git
synced 2026-01-21 04:52:20 +00:00
61 lines
1.5 KiB
C++
61 lines
1.5 KiB
C++
#include <fit/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 FIT_HAS_NOEXCEPT_DEDUCTION
|
|
FIT_TEST_CASE()
|
|
{
|
|
static_assert(noexcept(fit::repeat(std::integral_constant<int, 5>())(increment())(1)), "noexcept repeat");
|
|
static_assert(noexcept(fit::repeat(5)(increment())(1)), "noexcept repeat");
|
|
}
|
|
#endif
|
|
|
|
FIT_TEST_CASE()
|
|
{
|
|
FIT_TEST_CHECK(fit::repeat(std::integral_constant<int, 5>())(increment())(1) == 6);
|
|
FIT_STATIC_TEST_CHECK(fit::repeat(std::integral_constant<int, 5>())(increment())(1) == 6);
|
|
}
|
|
|
|
FIT_TEST_CASE()
|
|
{
|
|
FIT_TEST_CHECK(fit::repeat(5)(increment())(1) == 6);
|
|
FIT_STATIC_TEST_CHECK(fit::repeat(5)(increment())(1) == 6);
|
|
}
|
|
|
|
FIT_TEST_CASE()
|
|
{
|
|
int i = 5;
|
|
FIT_TEST_CHECK(fit::repeat(i)(increment())(1) == 6);
|
|
}
|
|
|
|
FIT_TEST_CASE()
|
|
{
|
|
static const int i = 5;
|
|
FIT_TEST_CHECK(fit::repeat(i)(increment())(1) == 6);
|
|
FIT_STATIC_TEST_CHECK(fit::repeat(i)(increment())(1) == 6);
|
|
}
|
|
|
|
// FIT_TEST_CASE()
|
|
// {
|
|
// FIT_TEST_CHECK(fit::repeat(std::numeric_limits<int>::max()/4)(increment())(0) == std::numeric_limits<int>::max()/4);
|
|
// }
|
|
|
|
FIT_TEST_CASE()
|
|
{
|
|
FIT_TEST_CHECK(fit::repeat(FIT_RECURSIVE_CONSTEXPR_DEPTH+4)(increment())(0) == FIT_RECURSIVE_CONSTEXPR_DEPTH+4);
|
|
#if FIT_HAS_RELAXED_CONSTEXPR
|
|
FIT_STATIC_TEST_CHECK(fit::repeat(FIT_RECURSIVE_CONSTEXPR_DEPTH+4)(increment())(0) == FIT_RECURSIVE_CONSTEXPR_DEPTH+4);
|
|
#endif
|
|
}
|