| 1 | /*! |
| 2 | @file |
| 3 | Forward declares `boost::hana::drop_front`. |
| 4 | |
| 5 | Copyright Louis Dionne 2013-2022 |
| 6 | Distributed under the Boost Software License, Version 1.0. |
| 7 | (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) |
| 8 | */ |
| 9 | |
| 10 | #ifndef BOOST_HANA_FWD_DROP_FRONT_HPP |
| 11 | #define BOOST_HANA_FWD_DROP_FRONT_HPP |
| 12 | |
| 13 | #include <boost/hana/config.hpp> |
| 14 | #include <boost/hana/core/when.hpp> |
| 15 | |
| 16 | |
| 17 | namespace boost { namespace hana { |
| 18 | //! Drop the first `n` elements of an iterable, and return the rest. |
| 19 | //! @ingroup group-Iterable |
| 20 | //! |
| 21 | //! Given an `Iterable` `xs` with a linearization of `[x1, x2, ...]` and |
| 22 | //! a non-negative `IntegralConstant` `n`, `drop_front(xs, n)` is an |
| 23 | //! iterable with the same tag as `xs` whose linearization is |
| 24 | //! `[xn+1, xn+2, ...]`. In particular, note that this function does not |
| 25 | //! mutate the original iterable in any way. If `n` is not given, it |
| 26 | //! defaults to an `IntegralConstant` with a value equal to `1`. |
| 27 | //! |
| 28 | //! In case `length(xs) <= n`, `drop_front` will simply drop the whole |
| 29 | //! iterable without failing, thus returning an empty iterable. This is |
| 30 | //! different from `drop_front_exactly`, which expects `n <= length(xs)` |
| 31 | //! but can be better optimized because of this additional guarantee. |
| 32 | //! |
| 33 | //! |
| 34 | //! @param xs |
| 35 | //! The iterable from which elements are dropped. |
| 36 | //! |
| 37 | //! @param n |
| 38 | //! A non-negative `IntegralConstant` representing the number of elements |
| 39 | //! to be dropped from the iterable. If `n` is not given, it defaults to |
| 40 | //! an `IntegralConstant` with a value equal to `1`. |
| 41 | //! |
| 42 | //! |
| 43 | //! Example |
| 44 | //! ------- |
| 45 | //! @include example/drop_front.cpp |
| 46 | #ifdef BOOST_HANA_DOXYGEN_INVOKED |
| 47 | constexpr auto drop_front = [](auto&& xs[, auto const& n]) { |
| 48 | return tag-dispatched; |
| 49 | }; |
| 50 | #else |
| 51 | template <typename It, typename = void> |
| 52 | struct drop_front_impl : drop_front_impl<It, when<true>> { }; |
| 53 | |
| 54 | struct drop_front_t { |
| 55 | template <typename Xs, typename N> |
| 56 | constexpr auto operator()(Xs&& xs, N const& n) const; |
| 57 | |
| 58 | template <typename Xs> |
| 59 | constexpr auto operator()(Xs&& xs) const; |
| 60 | }; |
| 61 | |
| 62 | BOOST_HANA_INLINE_VARIABLE constexpr drop_front_t drop_front{}; |
| 63 | #endif |
| 64 | }} // end namespace boost::hana |
| 65 | |
| 66 | #endif // !BOOST_HANA_FWD_DROP_FRONT_HPP |
| 67 | |