]>
Commit | Line | Data |
---|---|---|
7c673cae | 1 | |
b32b8144 | 2 | // (C) Copyright Kohei Takahashi 2014,2016 |
7c673cae FG |
3 | |
4 | // Use, modification and distribution are subject to the | |
5 | // Boost Software License, Version 1.0. (See accompanying file | |
6 | // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
7 | ||
8 | // See http://www.boost.org/libs/config for more information. | |
9 | ||
10 | // MACRO: BOOST_NO_CXX14_CONSTEXPR | |
11 | // TITLE: C++14 relaxed constexpr unavailable | |
12 | // DESCRIPTION: The compiler does not support C++14 relaxed constexpr | |
13 | ||
14 | namespace boost_no_cxx14_constexpr | |
15 | { | |
16 | ||
17 | namespace detail | |
18 | { | |
19 | template <class> struct void_ { typedef void type; }; | |
b32b8144 FG |
20 | |
21 | struct non_tmpl | |
22 | { | |
23 | constexpr int foo() const { return 1; } | |
24 | constexpr int foo() { return 0; } | |
25 | }; | |
26 | ||
27 | template <typename T> | |
28 | struct tmpl : non_tmpl { }; | |
7c673cae FG |
29 | } |
30 | ||
31 | // Test relaxed constexpr with dependent type; for more details, see comment of | |
32 | // BOOST_CXX14_CONSTEXPR definition in boost/config/compiler/clang.hpp . | |
33 | template <class T> | |
34 | constexpr typename detail::void_<T>::type decrement(T &value) | |
35 | { | |
36 | --value; | |
37 | } | |
38 | ||
b32b8144 FG |
39 | constexpr int non_cv_member(detail::non_tmpl x) |
40 | { | |
41 | return x.foo(); | |
42 | } | |
43 | ||
44 | template <typename T> | |
45 | constexpr int non_cv_member(detail::tmpl<T> x) | |
46 | { | |
47 | return x.foo(); | |
48 | } | |
49 | ||
7c673cae FG |
50 | constexpr int zero() |
51 | { | |
52 | int ret = 1; | |
53 | decrement(ret); | |
54 | return ret; | |
55 | } | |
56 | ||
b32b8144 FG |
57 | template <int v> struct compile_time_value |
58 | { | |
59 | static constexpr int value = v; | |
60 | }; | |
61 | ||
7c673cae FG |
62 | int test() |
63 | { | |
b32b8144 FG |
64 | return compile_time_value< |
65 | zero() | |
66 | + non_cv_member(detail::non_tmpl()) | |
67 | + non_cv_member(detail::tmpl<int>()) | |
68 | >::value; | |
7c673cae FG |
69 | } |
70 | ||
71 | } | |
72 |