]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/mp11/test/mp_for_each.cpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / libs / mp11 / test / mp_for_each.cpp
1
2 // Copyright 2017 Peter Dimov.
3 //
4 // Distributed under the Boost Software License, Version 1.0.
5 //
6 // See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt
8
9 #include <boost/mp11/detail/config.hpp>
10
11 #if BOOST_MP11_MSVC
12 # pragma warning( disable: 4503 ) // decorated name length exceeded
13 # pragma warning( disable: 4307 ) // '*': integral constant overflow
14 #endif
15
16 #include <boost/mp11/algorithm.hpp>
17 #include <boost/mp11/list.hpp>
18 #include <boost/core/lightweight_test.hpp>
19 #include <tuple>
20 #include <cstdint>
21
22 #if defined( BOOST_MP11_HAS_CXX14_CONSTEXPR )
23 # define CONSTEXPR14 constexpr
24 #else
25 # define CONSTEXPR14
26 #endif
27
28 struct F
29 {
30 int s;
31
32 CONSTEXPR14 void operator()( int ) { s = s * 10 + 1; }
33 CONSTEXPR14 void operator()( short ) { s = s * 10 + 2; }
34 CONSTEXPR14 void operator()( char ) { s = s * 10 + 3; }
35 };
36
37 struct G
38 {
39 std::uint32_t s;
40 CONSTEXPR14 void operator()( std::uint32_t i ) { s = s * 3 + i; }
41 };
42
43 using boost::mp11::mp_list;
44 using boost::mp11::mp_for_each;
45 using boost::mp11::mp_iota_c;
46
47 int main()
48 {
49 BOOST_TEST_EQ( (mp_for_each<mp_list<>>( 11 )), 11 );
50 BOOST_TEST_EQ( (mp_for_each<mp_list<int>>( F{0} ).s), 1 );
51 BOOST_TEST_EQ( (mp_for_each<mp_list<int, short>>( F{0} ).s), 12 );
52 BOOST_TEST_EQ( (mp_for_each<mp_list<int, short, char>>( F{0} ).s), 123 );
53
54 BOOST_TEST_EQ( (mp_for_each<std::tuple<>>( 11 )), 11 );
55 BOOST_TEST_EQ( (mp_for_each<std::tuple<int>>( F{0} ).s), 1 );
56 BOOST_TEST_EQ( (mp_for_each<std::tuple<int, short>>( F{0} ).s), 12 );
57 BOOST_TEST_EQ( (mp_for_each<std::tuple<int, short, char>>( F{0} ).s), 123 );
58
59 BOOST_TEST_EQ( (mp_for_each<std::pair<int, short>>( F{0} ).s), 12 );
60
61 #if BOOST_MP11_WORKAROUND( BOOST_MP11_MSVC, <= 1800 )
62 #else
63
64 using L = mp_iota_c<1089>;
65 std::uint32_t const R = 598075296;
66
67 BOOST_TEST_EQ( (mp_for_each<L>( G{0} ).s), R );
68
69 {
70 G g{0};
71 mp_for_each<L>( g );
72 BOOST_TEST_EQ( g.s, R );
73 }
74
75 #endif
76
77 #if defined( BOOST_MP11_NO_CONSTEXPR ) || ( !defined( __GLIBCXX__ ) && __cplusplus < 201400L )
78 #else
79
80 static_assert( mp_for_each<mp_list<>>( 11 ) == 11, "mp_for_each<mp_list<>>( 11 ) == 11" );
81 static_assert( mp_for_each<std::tuple<>>( 12 ) == 12, "mp_for_each<std::tuple<>>( 12 ) == 12" );
82
83 #endif
84
85 #if defined( BOOST_MP11_HAS_CXX14_CONSTEXPR )
86
87 constexpr auto r1 = mp_for_each<mp_list<int, short, char>>( F{0} );
88 static_assert( r1.s == 123, "r1.s == 123" );
89
90 constexpr auto r2 = mp_for_each<std::tuple<int, short, char>>( F{0} );
91 static_assert( r2.s == 123, "r2.s == 123" );
92
93 constexpr auto r3 = mp_for_each<std::pair<int, short>>( F{0} );
94 static_assert( r3.s == 12, "r3.s == 12" );
95
96 constexpr auto r4 = mp_for_each<L>( G{0} );
97 static_assert( r4.s == R, "r4.s == R" );
98
99 #endif
100
101 return boost::report_errors();
102 }