second.hpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*!
  2. @file
  3. Defines `boost::hana::second`.
  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_SECOND_HPP
  9. #define BOOST_HANA_SECOND_HPP
  10. #include <boost/hana/fwd/second.hpp>
  11. #include <boost/hana/concept/product.hpp>
  12. #include <boost/hana/config.hpp>
  13. #include <boost/hana/core/dispatch.hpp>
  14. BOOST_HANA_NAMESPACE_BEGIN
  15. //! @cond
  16. template <typename Pair>
  17. constexpr decltype(auto) second_t::operator()(Pair&& pair) const {
  18. using P = typename hana::tag_of<Pair>::type;
  19. using Second = BOOST_HANA_DISPATCH_IF(second_impl<P>,
  20. hana::Product<P>::value
  21. );
  22. #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
  23. static_assert(hana::Product<P>::value,
  24. "hana::second(pair) requires 'pair' to be a Product");
  25. #endif
  26. return Second::apply(static_cast<Pair&&>(pair));
  27. }
  28. //! @endcond
  29. template <typename P, bool condition>
  30. struct second_impl<P, when<condition>> : default_ {
  31. template <typename ...Args>
  32. static constexpr auto apply(Args&& ...) = delete;
  33. };
  34. BOOST_HANA_NAMESPACE_END
  35. #endif // !BOOST_HANA_SECOND_HPP