• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 // Copyright 2015 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 
10 #if defined(_MSC_VER)
11 #pragma warning( disable: 4244 ) // 'initializing': conversion from 'int' to 'char', possible loss of data
12 #endif
13 
14 #include <boost/mp11/tuple.hpp>
15 #include <boost/mp11/detail/config.hpp>
16 
17 // Technically std::tuple isn't constexpr enabled in C++11, but it works with libstdc++
18 
19 #if defined( BOOST_MP11_NO_CONSTEXPR ) || ( !defined(_MSC_VER) && !defined( __GLIBCXX__ ) && __cplusplus < 201400L )
20 
main()21 int main() {}
22 
23 #else
24 
25 #include <tuple>
26 #include <array>
27 #include <utility>
28 
f(int x,int y,int z)29 constexpr int f( int x, int y, int z )
30 {
31     return x * 100 + y * 10 + z;
32 }
33 
g(int x,int y)34 constexpr int g( int x, int y )
35 {
36     return x * 10 + y;
37 }
38 
h()39 constexpr int h()
40 {
41     return 11;
42 }
43 
main()44 int main()
45 {
46     {
47         constexpr std::tuple<int, short, char> tp{ 1, 2, 3 };
48         constexpr auto r = boost::mp11::tuple_apply( f, tp );
49         static_assert( r == 123, "r == 123" );
50     }
51 
52     {
53         constexpr std::pair<short, char> tp{ 1, 2 };
54         constexpr auto r = boost::mp11::tuple_apply( g, tp );
55         static_assert( r == 12, "r == 12" );
56     }
57 
58     {
59         constexpr std::array<short, 3> tp{{ 1, 2, 3 }};
60         constexpr auto r = boost::mp11::tuple_apply( f, tp );
61         static_assert( r == 123, "r == 123" );
62     }
63 
64 #if defined( __clang_major__ ) && __clang_major__ == 3 && __clang_minor__ < 9
65 // "error: default initialization of an object of const type 'const std::tuple<>' without a user-provided default constructor"
66 #else
67 
68     {
69         constexpr std::tuple<> tp;
70         constexpr auto r = boost::mp11::tuple_apply( h, tp );
71         static_assert( r == 11, "r == 11" );
72     }
73 
74 #endif
75 }
76 
77 #endif
78