]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/hana/test/concept/integral_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)
5 #include <boost/hana/concept/constant.hpp>
6 #include <boost/hana/concept/integral_constant.hpp>
7 #include <boost/hana/core/when.hpp>
8 #include <boost/hana/fwd/core/to.hpp>
9 #include <boost/hana/value.hpp>
10 namespace hana
= boost::hana
;
13 // Define a simple model of IntegralConstant
14 struct constant_tag
{ using value_type
= int; };
17 static constexpr int value
= i
;
18 using hana_tag
= constant_tag
;
21 namespace boost
{ namespace hana
{
23 struct IntegralConstant
<constant_tag
> {
24 static constexpr bool value
= true;
27 template <typename From
>
28 struct to_impl
<constant_tag
, From
, when
<IntegralConstant
<From
>::value
>> {
30 static constexpr auto apply(N
const&)
31 { return constant
<N::value
>{}; }
35 // Make sure we really satisfy IntegralConstant<>.
36 static_assert(hana::IntegralConstant
<constant
<0>>::value
, "");
37 static_assert(hana::IntegralConstant
<constant
<1>>::value
, "");
38 static_assert(hana::IntegralConstant
<constant
<2>>::value
, "");
40 // Make sure we're also a model of Constant automatically.
41 static_assert(hana::Constant
<constant
<0>>::value
, "");
42 static_assert(hana::Constant
<constant
<1>>::value
, "");
43 static_assert(hana::Constant
<constant
<2>>::value
, "");
45 // Make sure we have the hana::value<> function defined automatically.
46 static_assert(hana::value
<constant
<0>>() == 0, "");
47 static_assert(hana::value
<constant
<1>>() == 1, "");
48 static_assert(hana::value
<constant
<2>>() == 2, "");
49 static_assert(hana::value
<constant
<3>>() == 3, "");