front.hpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*!
  2. @file
  3. Forward declares `boost::hana::front`.
  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_FRONT_HPP
  9. #define BOOST_HANA_FWD_FRONT_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 non-empty iterable.
  14. //! @ingroup group-Iterable
  15. //!
  16. //! Given a non-empty Iterable `xs` with a linearization of `[x1, ..., xN]`,
  17. //! `front(xs)` is equal to `x1`. If `xs` is empty, it is an error to
  18. //! use this function. Equivalently, `front(xs)` must be equivalent to
  19. //! `at_c<0>(xs)`, and that regardless of the value category of `xs`
  20. //! (`front` must respect the reference semantics of `at`).
  21. //!
  22. //!
  23. //! Example
  24. //! -------
  25. //! @include example/front.cpp
  26. #ifdef BOOST_HANA_DOXYGEN_INVOKED
  27. constexpr auto front = [](auto&& xs) -> decltype(auto) {
  28. return tag-dispatched;
  29. };
  30. #else
  31. template <typename It, typename = void>
  32. struct front_impl : front_impl<It, when<true>> { };
  33. struct front_t {
  34. template <typename Xs>
  35. constexpr decltype(auto) operator()(Xs&& xs) const;
  36. };
  37. constexpr front_t front{};
  38. #endif
  39. BOOST_HANA_NAMESPACE_END
  40. #endif // !BOOST_HANA_FWD_FRONT_HPP