]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/hof/test/repeat_while.cpp
update sources to ceph Nautilus 14.2.1
[ceph.git] / ceph / src / boost / libs / hof / test / repeat_while.cpp
1 /*=============================================================================
2 Copyright (c) 2017 Paul Fultz II
3 repeat_while.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_while.hpp>
8 #include <boost/hof/reveal.hpp>
9 #include "test.hpp"
10
11 // TODO: Test default construction, and static initialization
12
13 struct increment_constant
14 {
15 template<class T>
16 constexpr std::integral_constant<int, T::value + 1> operator()(T) const noexcept
17 {
18 return std::integral_constant<int, T::value + 1>();
19 }
20 };
21
22 struct increment
23 {
24 template<class T>
25 constexpr T operator()(T x) const noexcept
26 {
27 return x + 1;
28 }
29 };
30
31 struct not_6_constant
32 {
33 template<class T>
34 constexpr std::integral_constant<bool, (T::value != 6)>
35 operator()(T) const noexcept
36 {
37 return std::integral_constant<bool, (T::value != 6)>();
38 }
39 };
40
41 struct not_6
42 {
43 template<class T>
44 constexpr bool operator()(T x) const noexcept
45 {
46 return x != 6;
47 }
48 };
49
50 struct not_limit
51 {
52 template<class T>
53 constexpr bool operator()(T x) const
54 {
55 return x != (BOOST_HOF_RECURSIVE_CONSTEXPR_DEPTH+4);
56 }
57 };
58
59 #if BOOST_HOF_HAS_NOEXCEPT_DEDUCTION
60 BOOST_HOF_TEST_CASE()
61 {
62 static_assert(noexcept(boost::hof::repeat_while(not_6())(increment())(1)), "noexcept repeat_while");
63 static_assert(noexcept(boost::hof::repeat_while(not_6_constant())(increment_constant())(std::integral_constant<int, 1>())), "noexcept repeat_while");
64 }
65 #endif
66
67 BOOST_HOF_TEST_CASE()
68 {
69 static_assert
70 (
71 std::is_same<
72 std::integral_constant<int, 6>,
73 decltype(boost::hof::repeat_while(not_6_constant())(increment_constant())(std::integral_constant<int, 1>()))
74 >::value,
75 "Error"
76 );
77
78 std::integral_constant<int, 6> x = boost::hof::repeat_while(not_6_constant())(increment_constant())(std::integral_constant<int, 1>());
79 boost::hof::test::unused(x);
80 }
81
82 BOOST_HOF_TEST_CASE()
83 {
84 BOOST_HOF_STATIC_TEST_CHECK(boost::hof::repeat_while(not_6())(increment())(1) == 6);
85 BOOST_HOF_TEST_CHECK(boost::hof::repeat_while(not_6())(increment())(1) == 6);
86 BOOST_HOF_TEST_CHECK(boost::hof::reveal(boost::hof::repeat_while(not_6())(increment()))(1) == 6);
87 }
88
89 BOOST_HOF_TEST_CASE()
90 {
91 BOOST_HOF_TEST_CHECK(boost::hof::repeat_while(not_limit())(increment())(1) == BOOST_HOF_RECURSIVE_CONSTEXPR_DEPTH+4);
92 #if BOOST_HOF_HAS_RELAXED_CONSTEXPR
93 BOOST_HOF_STATIC_TEST_CHECK(boost::hof::repeat_while(not_limit())(increment())(1) == BOOST_HOF_RECURSIVE_CONSTEXPR_DEPTH+4);
94 #endif
95 }