minimal.hpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. #ifndef TEST_CONCEPT_CONSTANT_MINIMAL_HPP
  5. #define TEST_CONCEPT_CONSTANT_MINIMAL_HPP
  6. #include <boost/hana/concept/constant.hpp>
  7. #include <boost/hana/core/when.hpp>
  8. #include <boost/hana/fwd/core/to.hpp>
  9. #include <boost/hana/value.hpp>
  10. template <typename T>
  11. struct minimal_constant_tag {
  12. using value_type = T;
  13. };
  14. template <typename T, T v>
  15. struct minimal_constant {
  16. using hana_tag = minimal_constant_tag<T>;
  17. static constexpr T value_ = v;
  18. };
  19. namespace boost { namespace hana {
  20. template <typename T>
  21. struct value_impl<minimal_constant_tag<T>> {
  22. template <typename N>
  23. static constexpr T apply() { return N::value_; }
  24. };
  25. template <typename T, typename C>
  26. struct to_impl<minimal_constant_tag<T>, C, hana::when<
  27. hana::Constant<C>::value &&
  28. hana::is_convertible<typename C::value_type, T>::value
  29. >>
  30. : hana::embedding<hana::is_embedded<typename C::value_type, T>::value>
  31. {
  32. template <typename N>
  33. static constexpr auto apply(N const&)
  34. { return minimal_constant<T, hana::value<N>()>{}; }
  35. };
  36. }} // end namespace boost::hana
  37. #endif // !TEST_CONCEPT_CONSTANT_MINIMAL_HPP