minimal_product.hpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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_SUPPORT_MINIMAL_PRODUCT_HPP
  5. #define TEST_SUPPORT_MINIMAL_PRODUCT_HPP
  6. #include <boost/hana/fwd/core/make.hpp>
  7. #include <boost/hana/fwd/first.hpp>
  8. #include <boost/hana/fwd/second.hpp>
  9. #include <type_traits>
  10. struct MinimalProduct;
  11. template <typename X, typename Y>
  12. struct product_t {
  13. X fst;
  14. Y snd;
  15. using hana_tag = MinimalProduct;
  16. };
  17. struct make_minimal_product {
  18. template <typename T, typename U>
  19. constexpr product_t<typename std::decay<T>::type,
  20. typename std::decay<U>::type>
  21. operator()(T&& t, U&& u) const {
  22. return {static_cast<T&&>(t), static_cast<U&&>(u)};
  23. }
  24. };
  25. constexpr make_minimal_product minimal_product{};
  26. namespace boost { namespace hana {
  27. //////////////////////////////////////////////////////////////////////////
  28. // Product
  29. //////////////////////////////////////////////////////////////////////////
  30. template <>
  31. struct make_impl<MinimalProduct> {
  32. template <typename X, typename Y>
  33. static constexpr auto apply(X x, Y y)
  34. { return ::minimal_product(x, y); }
  35. };
  36. template <>
  37. struct first_impl<MinimalProduct> {
  38. template <typename P>
  39. static constexpr decltype(auto) apply(P&& p)
  40. { return p.fst; }
  41. };
  42. template <>
  43. struct second_impl<MinimalProduct> {
  44. template <typename P>
  45. static constexpr decltype(auto) apply(P&& p)
  46. { return p.snd; }
  47. };
  48. }} // end namespace boost::hana
  49. #endif // !TEST_SUPPORT_MINIMAL_PRODUCT_HPP