back.hpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*!
  2. @file
  3. Forward declares `boost::hana::back`.
  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_BACK_HPP
  9. #define BOOST_HANA_FWD_BACK_HPP
  10. #include <boost/hana/config.hpp>
  11. #include <boost/hana/core/when.hpp>
  12. BOOST_HANA_NAMESPACE_BEGIN
  13. //! Returns the last element of a non-empty and finite iterable.
  14. //! @ingroup group-Iterable
  15. //!
  16. //! Given a non-empty and finite iterable `xs` with a linearization of
  17. //! `[x1, ..., xN]`, `back(xs)` is equal to `xN`. Equivalently, `back(xs)`
  18. //! must be equivalent to `at_c<N-1>(xs)`, and that regardless of the
  19. //! value category of `xs` (`back` must respect the reference semantics
  20. //! of `at`).
  21. //!
  22. //!
  23. //! Example
  24. //! -------
  25. //! @include example/back.cpp
  26. #ifdef BOOST_HANA_DOXYGEN_INVOKED
  27. constexpr auto back = [](auto&& xs) -> decltype(auto) {
  28. return tag-dispatched;
  29. };
  30. #else
  31. template <typename It, typename = void>
  32. struct back_impl : back_impl<It, when<true>> { };
  33. struct back_t {
  34. template <typename Xs>
  35. constexpr decltype(auto) operator()(Xs&& xs) const;
  36. };
  37. constexpr back_t back{};
  38. #endif
  39. BOOST_HANA_NAMESPACE_END
  40. #endif // !BOOST_HANA_FWD_BACK_HPP