]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/hana/test/assert/constant.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / hana / test / assert / constant.cpp
1 // Copyright Louis Dionne 2013-2016
2 // Distributed under the Boost Software License, Version 1.0.
3 // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
4
5 #include <boost/hana/assert.hpp>
6
7 #include <support/cnumeric.hpp>
8 namespace hana = boost::hana;
9
10
11 template <bool value>
12 auto constant_bool() { return make_cnumeric<bool, value>(); }
13
14 template <bool value>
15 constexpr auto constexpr_constant_bool() { return make_cnumeric<bool, value>(); }
16
17
18 // Make sure it works at global scope
19 BOOST_HANA_CONSTANT_ASSERT(constant_bool<true>());
20 BOOST_HANA_CONSTANT_ASSERT_MSG(constant_bool<true>(), "message");
21
22 // Make sure it works at namespace scope
23 namespace ns {
24 BOOST_HANA_CONSTANT_ASSERT(constant_bool<true>());
25 BOOST_HANA_CONSTANT_ASSERT_MSG(constant_bool<true>(), "message");
26 }
27
28 // Make sure it works in a constexpr context
29 constexpr bool constexpr_context() {
30 BOOST_HANA_CONSTANT_ASSERT(constexpr_constant_bool<true>());
31 BOOST_HANA_CONSTANT_ASSERT_MSG(constexpr_constant_bool<true>(), "message");
32 return true;
33 }
34 static_assert(constexpr_context(), "");
35
36
37 int main() {
38 // Make sure it works at function scope
39 BOOST_HANA_CONSTANT_ASSERT(constant_bool<true>());
40 BOOST_HANA_CONSTANT_ASSERT_MSG(constant_bool<true>(), "message");
41
42 // Make sure it works inside a lambda
43 auto lambda = []{
44 BOOST_HANA_CONSTANT_ASSERT(constant_bool<true>());
45 BOOST_HANA_CONSTANT_ASSERT_MSG(constant_bool<true>(), "message");
46 };
47 lambda();
48
49 // Make sure we can reference a local variable
50 auto yes = constant_bool<true>();
51 BOOST_HANA_CONSTANT_ASSERT(yes);
52 BOOST_HANA_CONSTANT_ASSERT_MSG(yes, "message");
53 }