extract.hpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*!
  2. @file
  3. Defines `boost::hana::extract`.
  4. Copyright Louis Dionne 2013-2022
  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_EXTRACT_HPP
  9. #define BOOST_HANA_EXTRACT_HPP
  10. #include <boost/hana/fwd/extract.hpp>
  11. #include <boost/hana/concept/comonad.hpp>
  12. #include <boost/hana/config.hpp>
  13. #include <boost/hana/core/dispatch.hpp>
  14. namespace boost { namespace hana {
  15. //! @cond
  16. template <typename W_>
  17. constexpr decltype(auto) extract_t::operator()(W_&& w) const {
  18. using W = typename hana::tag_of<W_>::type;
  19. using Extract = BOOST_HANA_DISPATCH_IF(extract_impl<W>,
  20. hana::Comonad<W>::value
  21. );
  22. #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
  23. static_assert(hana::Comonad<W>::value,
  24. "hana::extract(w) requires 'w' to be a Comonad");
  25. #endif
  26. return Extract::apply(static_cast<W_&&>(w));
  27. }
  28. //! @endcond
  29. template <typename W, bool condition>
  30. struct extract_impl<W, when<condition>> : default_ {
  31. template <typename ...Args>
  32. static constexpr auto apply(Args&& ...args) = delete;
  33. };
  34. }} // end namespace boost::hana
  35. #endif // !BOOST_HANA_EXTRACT_HPP