lift.hpp 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*!
  2. @file
  3. Defines `boost::hana::lift`.
  4. @copyright Louis Dionne 2013-2017
  5. Distributed under the Boost Software License, Version 1.0.
  6. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  7. */
  8. #ifndef BOOST_HANA_LIFT_HPP
  9. #define BOOST_HANA_LIFT_HPP
  10. #include <boost/hana/fwd/lift.hpp>
  11. #include <boost/hana/concept/applicative.hpp>
  12. #include <boost/hana/concept/sequence.hpp>
  13. #include <boost/hana/config.hpp>
  14. #include <boost/hana/core/dispatch.hpp>
  15. #include <boost/hana/core/make.hpp>
  16. BOOST_HANA_NAMESPACE_BEGIN
  17. //! @cond
  18. template <typename A>
  19. template <typename X>
  20. constexpr auto lift_t<A>::operator()(X&& x) const {
  21. #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
  22. static_assert(hana::Applicative<A>::value,
  23. "hana::lift<A> requires 'A' to be an Applicative");
  24. #endif
  25. using Lift = BOOST_HANA_DISPATCH_IF(lift_impl<A>,
  26. hana::Applicative<A>::value
  27. );
  28. return Lift::apply(static_cast<X&&>(x));
  29. }
  30. //! @endcond
  31. template <typename A, bool condition>
  32. struct lift_impl<A, when<condition>> : default_ {
  33. template <typename ...Args>
  34. static constexpr auto apply(Args&& ...args) = delete;
  35. };
  36. template <typename S>
  37. struct lift_impl<S, when<Sequence<S>::value>> {
  38. template <typename X>
  39. static constexpr decltype(auto) apply(X&& x)
  40. { return hana::make<S>(static_cast<X&&>(x)); }
  41. };
  42. BOOST_HANA_NAMESPACE_END
  43. #endif // !BOOST_HANA_LIFT_HPP