• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright Louis Dionne 2013-2017
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 #ifndef TEST_CONCEPT_CONSTANT_MINIMAL_HPP
6 #define TEST_CONCEPT_CONSTANT_MINIMAL_HPP
7 
8 #include <boost/hana/concept/constant.hpp>
9 #include <boost/hana/core/when.hpp>
10 #include <boost/hana/fwd/core/to.hpp>
11 #include <boost/hana/value.hpp>
12 
13 
14 template <typename T>
15 struct minimal_constant_tag {
16     using value_type = T;
17 };
18 
19 template <typename T, T v>
20 struct minimal_constant {
21     using hana_tag = minimal_constant_tag<T>;
22     static constexpr T value_ = v;
23 };
24 
25 namespace boost { namespace hana {
26     template <typename T>
27     struct value_impl<minimal_constant_tag<T>> {
28         template <typename N>
applyboost::hana::value_impl29         static constexpr T apply() { return N::value_; }
30     };
31 
32     template <typename T, typename C>
33     struct to_impl<minimal_constant_tag<T>, C, hana::when<
34         hana::Constant<C>::value &&
35         hana::is_convertible<typename C::value_type, T>::value
36     >>
37         : hana::embedding<hana::is_embedded<typename C::value_type, T>::value>
38     {
39         template <typename N>
applyboost::hana::to_impl40         static constexpr auto apply(N const&)
41         { return minimal_constant<T, hana::value<N>()>{}; }
42     };
43 }} // end namespace boost::hana
44 
45 #endif // !TEST_CONCEPT_CONSTANT_MINIMAL_HPP
46