• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1
2//  (C) Copyright Kohei Takahashi 2014,2016
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
14namespace boost_no_cxx14_constexpr
15{
16
17namespace detail
18{
19    template <class> struct void_ { typedef void type; };
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 { };
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 .
33template <class T>
34constexpr typename detail::void_<T>::type decrement(T &value)
35{
36    --value;
37}
38
39constexpr int non_cv_member(detail::non_tmpl x)
40{
41    return x.foo();
42}
43
44template <typename T>
45constexpr int non_cv_member(detail::tmpl<T> x)
46{
47    return x.foo();
48}
49
50constexpr int zero()
51{
52    int ret = 1;
53    decrement(ret);
54    return ret;
55}
56
57template <int v> struct compile_time_value
58{
59    static constexpr int value = v;
60};
61
62int test()
63{
64    return compile_time_value<
65        zero()
66      + non_cv_member(detail::non_tmpl())
67      + non_cv_member(detail::tmpl<int>())
68    >::value;
69}
70
71}
72
73