first.hpp 1.4 KB

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