drop_front.hpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*!
  2. @file
  3. Forward declares `boost::hana::drop_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_DROP_FRONT_HPP
  9. #define BOOST_HANA_FWD_DROP_FRONT_HPP
  10. #include <boost/hana/config.hpp>
  11. #include <boost/hana/core/when.hpp>
  12. BOOST_HANA_NAMESPACE_BEGIN
  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(xs, n)` is an
  18. //! 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. //! In case `length(xs) <= n`, `drop_front` will simply drop the whole
  24. //! iterable without failing, thus returning an empty iterable. This is
  25. //! different from `drop_front_exactly`, which expects `n <= length(xs)`
  26. //! but can be better optimized because of this additional guarantee.
  27. //!
  28. //!
  29. //! @param xs
  30. //! The iterable from which elements are dropped.
  31. //!
  32. //! @param n
  33. //! A non-negative `IntegralConstant` representing the number of elements
  34. //! to be dropped from the iterable. If `n` is not given, it defaults to
  35. //! an `IntegralConstant` with a value equal to `1`.
  36. //!
  37. //!
  38. //! Example
  39. //! -------
  40. //! @include example/drop_front.cpp
  41. #ifdef BOOST_HANA_DOXYGEN_INVOKED
  42. constexpr auto drop_front = [](auto&& xs[, auto const& n]) {
  43. return tag-dispatched;
  44. };
  45. #else
  46. template <typename It, typename = void>
  47. struct drop_front_impl : drop_front_impl<It, when<true>> { };
  48. struct drop_front_t {
  49. template <typename Xs, typename N>
  50. constexpr auto operator()(Xs&& xs, N const& n) const;
  51. template <typename Xs>
  52. constexpr auto operator()(Xs&& xs) const;
  53. };
  54. constexpr drop_front_t drop_front{};
  55. #endif
  56. BOOST_HANA_NAMESPACE_END
  57. #endif // !BOOST_HANA_FWD_DROP_FRONT_HPP