1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
// Copyright Louis Dionne 2013-2017
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
#ifndef TEST_SUPPORT_CNUMERIC_HPP
#define TEST_SUPPORT_CNUMERIC_HPP
#include <boost/hana/concept/integral_constant.hpp>
#include <boost/hana/core/when.hpp>
#include <boost/hana/fwd/core/to.hpp>
#include <boost/hana/fwd/equal.hpp>
#include <boost/hana/fwd/less.hpp>
template <typename T>
struct CNumeric { using value_type = T; };
template <typename T, T v>
struct cnumeric_t {
static constexpr T value = v;
using hana_tag = CNumeric<T>;
constexpr operator T() const { return value; }
};
template <typename T, T v>
constexpr cnumeric_t<T, v> cnumeric{};
template <typename T, T v>
constexpr cnumeric_t<T, v> make_cnumeric() { return {}; }
namespace boost { namespace hana {
// Constant and IntegralConstant
template <typename T>
struct IntegralConstant<CNumeric<T>> {
static constexpr bool value = true;
};
template <typename T, typename C>
struct to_impl<CNumeric<T>, C, when<
hana::IntegralConstant<C>::value
>>
: embedding<is_embedded<typename C::value_type, T>::value>
{
template <typename N>
static constexpr auto apply(N const&)
{ return cnumeric<T, N::value>; }
};
// Comparable
template <typename T, typename U>
struct equal_impl<CNumeric<T>, CNumeric<U>> {
template <typename X, typename Y>
static constexpr auto apply(X const&, Y const&)
{ return cnumeric<bool, X::value == Y::value>; }
};
// Orderable
template <typename T, typename U>
struct less_impl<CNumeric<T>, CNumeric<U>> {
template <typename X, typename Y>
static constexpr auto apply(X const&, Y const&)
{ return cnumeric<bool, (X::value < Y::value)>; }
};
}} // end namespace boost::hana
#endif // !TEST_SUPPORT_CNUMERIC_HPP
|