drop_back.hpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*!
  2. @file
  3. Forward declares `boost::hana::drop_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_DROP_BACK_HPP
  9. #define BOOST_HANA_FWD_DROP_BACK_HPP
  10. #include <boost/hana/config.hpp>
  11. #include <boost/hana/core/when.hpp>
  12. BOOST_HANA_NAMESPACE_BEGIN
  13. //! Drop the last `n` elements of a finite sequence, and return the rest.
  14. //! @ingroup group-Sequence
  15. //!
  16. //! Given a finite `Sequence` `xs` with a linearization of `[x1, ..., xm]`
  17. //! and a non-negative `IntegralConstant` `n`, `drop_back(xs, n)` is a
  18. //! sequence with the same tag as `xs` whose linearization is
  19. //! `[x1, ..., xm-n]`. If `n` is not given, it defaults to an
  20. //! `IntegralConstant` with a value equal to `1`.
  21. //!
  22. //! In case `length(xs) <= n`, `drop_back` will simply drop the whole
  23. //! sequence without failing, thus returning an empty sequence.
  24. //!
  25. //!
  26. //! @param xs
  27. //! The sequence from which elements are dropped.
  28. //!
  29. //! @param n
  30. //! A non-negative `IntegralConstant` representing the number of elements
  31. //! to be dropped from the end of the sequence. If `n` is not given, it
  32. //! defaults to an `IntegralConstant` with a value equal to `1`.
  33. //!
  34. //!
  35. //! Example
  36. //! -------
  37. //! @include example/drop_back.cpp
  38. #ifdef BOOST_HANA_DOXYGEN_INVOKED
  39. constexpr auto drop_back = [](auto&& xs[, auto const& n]) {
  40. return tag-dispatched;
  41. };
  42. #else
  43. template <typename S, typename = void>
  44. struct drop_back_impl : drop_back_impl<S, when<true>> { };
  45. struct drop_back_t {
  46. template <typename Xs, typename N>
  47. constexpr auto operator()(Xs&& xs, N const& n) const;
  48. template <typename Xs>
  49. constexpr auto operator()(Xs&& xs) const;
  50. };
  51. constexpr drop_back_t drop_back{};
  52. #endif
  53. BOOST_HANA_NAMESPACE_END
  54. #endif // !BOOST_HANA_FWD_DROP_BACK_HPP