second.hpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*!
  2. @file
  3. Forward declares `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_FWD_SECOND_HPP
  9. #define BOOST_HANA_FWD_SECOND_HPP
  10. #include <boost/hana/config.hpp>
  11. #include <boost/hana/core/when.hpp>
  12. BOOST_HANA_NAMESPACE_BEGIN
  13. //! Returns the second element of a pair.
  14. //! @ingroup group-Product
  15. //!
  16. //! Note that if the `Product` actually stores the elements it contains,
  17. //! `hana::second` is required to return a lvalue reference, a lvalue
  18. //! reference to const or a rvalue reference to the second element, where
  19. //! the type of reference must match that of the pair passed to `second`.
  20. //! If the `Product` does not store the elements it contains (i.e. it
  21. //! generates them on demand), this requirement is dropped.
  22. //!
  23. //! Example
  24. //! -------
  25. //! @include example/second.cpp
  26. #ifdef BOOST_HANA_DOXYGEN_INVOKED
  27. constexpr auto second = [](auto&& product) -> decltype(auto) {
  28. return tag-dispatched;
  29. };
  30. #else
  31. template <typename P, typename = void>
  32. struct second_impl : second_impl<P, when<true>> { };
  33. struct second_t {
  34. template <typename Pair>
  35. constexpr decltype(auto) operator()(Pair&& pair) const;
  36. };
  37. constexpr second_t second{};
  38. #endif
  39. BOOST_HANA_NAMESPACE_END
  40. #endif // !BOOST_HANA_FWD_SECOND_HPP