1 // Copyright 2015, 2020 Peter Dimov
2 // Copyright 2020 Hans Dembinski
3 //
4 // Distributed under the Boost Software License, Version 1.0.
5 // https://www.boost.org/LICENSE_1_0.txt
6
7 #include <boost/mp11/tuple.hpp>
8 #include <boost/mp11/detail/config.hpp>
9
10 // Technically std::tuple isn't constexpr enabled in C++11, but it works with libstdc++
11
12 #if defined( BOOST_MP11_NO_CONSTEXPR ) || ( !defined(_MSC_VER) && !defined( __GLIBCXX__ ) && __cplusplus < 201400L ) || BOOST_MP11_WORKAROUND( BOOST_MP11_GCC, < 40800 )
13
main()14 int main() {}
15
16 #else
17
18 #include <tuple>
19 #include <utility>
20
f(int x)21 constexpr int f( int x )
22 {
23 return x + 1;
24 }
25
g(int x,int y)26 constexpr int g( int x, int y )
27 {
28 return x + y + 1;
29 }
30
31 #define STATIC_ASSERT(...) static_assert(__VA_ARGS__, #__VA_ARGS__)
32
main()33 int main()
34 {
35 {
36 constexpr std::tuple<int, int, int> tp( 1, 2, 3 );
37
38 constexpr auto r = boost::mp11::tuple_transform( f, tp );
39
40 STATIC_ASSERT( r == std::make_tuple( 2, 3, 4 ) );
41 }
42
43 {
44 constexpr std::tuple<int, int> tp1( 1, 2 );
45 constexpr std::pair<int, int> tp2( 3, 4 );
46
47 constexpr auto r = boost::mp11::tuple_transform( g, tp1, tp2 );
48
49 STATIC_ASSERT( r == std::make_tuple( 5, 7 ) );
50 }
51
52 #if defined( __clang_major__ ) && __clang_major__ == 3 && __clang_minor__ < 9
53 // "error: default initialization of an object of const type 'const std::tuple<>' without a user-provided default constructor"
54 #else
55
56 {
57 constexpr std::tuple<> tp;
58 constexpr std::tuple<> r = boost::mp11::tuple_transform( f, tp );
59 (void)r;
60 }
61
62 #endif
63 }
64
65 #endif
66