drop_front_exactly.hpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*!
  2. @file
  3. Forward declares `boost::hana::drop_front_exactly`.
  4. Copyright Louis Dionne 2013-2022
  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_FRONT_EXACTLY_HPP
  9. #define BOOST_HANA_FWD_DROP_FRONT_EXACTLY_HPP
  10. #include <boost/hana/config.hpp>
  11. #include <boost/hana/core/when.hpp>
  12. namespace boost { namespace hana {
  13. //! Drop the first `n` elements of an iterable, and return the rest.
  14. //! @ingroup group-Iterable
  15. //!
  16. //! Given an `Iterable` `xs` with a linearization of `[x1, x2, ...]` and
  17. //! a non-negative `IntegralConstant` `n`, `drop_front_exactly(xs, n)` is
  18. //! an iterable with the same tag as `xs` whose linearization is
  19. //! `[xn+1, xn+2, ...]`. In particular, note that this function does not
  20. //! mutate the original iterable in any way. If `n` is not given, it
  21. //! defaults to an `IntegralConstant` with a value equal to `1`.
  22. //!
  23. //! It is an error to use `drop_front_exactly` with `n > length(xs)`. This
  24. //! additional guarantee allows `drop_front_exactly` to be better optimized
  25. //! than the `drop_front` function, which allows `n > length(xs)`.
  26. //!
  27. //!
  28. //! @param xs
  29. //! The iterable from which elements are dropped.
  30. //!
  31. //! @param n
  32. //! A non-negative `IntegralConstant` representing the number of elements
  33. //! to be dropped from the iterable. In addition to being non-negative,
  34. //! `n` must be less than or equal to the number of elements in `xs`.
  35. //! If `n` is not given, it defaults to an `IntegralConstant` with a value
  36. //! equal to `1`.
  37. //!
  38. //!
  39. //! Example
  40. //! -------
  41. //! @include example/drop_front_exactly.cpp
  42. #ifdef BOOST_HANA_DOXYGEN_INVOKED
  43. constexpr auto drop_front_exactly = [](auto&& xs[, auto const& n]) {
  44. return tag-dispatched;
  45. };
  46. #else
  47. template <typename It, typename = void>
  48. struct drop_front_exactly_impl : drop_front_exactly_impl<It, when<true>> { };
  49. struct drop_front_exactly_t {
  50. template <typename Xs, typename N>
  51. constexpr auto operator()(Xs&& xs, N const& n) const;
  52. template <typename Xs>
  53. constexpr auto operator()(Xs&& xs) const;
  54. };
  55. BOOST_HANA_INLINE_VARIABLE constexpr drop_front_exactly_t drop_front_exactly{};
  56. #endif
  57. }} // end namespace boost::hana
  58. #endif // !BOOST_HANA_FWD_DROP_FRONT_EXACTLY_HPP