]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /*! |
2 | @file | |
3 | Forward declares `boost::hana::take_back`. | |
4 | ||
5 | @copyright Louis Dionne 2013-2016 | |
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_TAKE_BACK_HPP | |
11 | #define BOOST_HANA_FWD_TAKE_BACK_HPP | |
12 | ||
13 | #include <boost/hana/config.hpp> | |
14 | #include <boost/hana/core/when.hpp> | |
15 | ||
16 | #include <cstddef> | |
17 | ||
18 | ||
19 | BOOST_HANA_NAMESPACE_BEGIN | |
20 | //! Returns the last `n` elements of a sequence, or the whole sequence | |
21 | //! if the sequence has less than `n` elements. | |
22 | //! @ingroup group-Sequence | |
23 | //! | |
24 | //! Given a `Sequence` `xs` and an `IntegralConstant` `n`, `take_back(xs, n)` | |
25 | //! is a new sequence containing the last `n` elements of `xs`, in the | |
26 | //! same order. If `length(xs) <= n`, the whole sequence is returned and | |
27 | //! no error is triggered. | |
28 | //! | |
29 | //! | |
30 | //! @param xs | |
31 | //! The sequence to take the elements from. | |
32 | //! | |
33 | //! @param n | |
34 | //! A non-negative `IntegralConstant` representing the number of elements | |
35 | //! to keep in the resulting sequence. | |
36 | //! | |
37 | //! | |
38 | //! Example | |
39 | //! ------- | |
40 | //! @include example/take_back.cpp | |
41 | #ifdef BOOST_HANA_DOXYGEN_INVOKED | |
42 | constexpr auto take_back = [](auto&& xs, auto const& n) { | |
43 | return tag-dispatched; | |
44 | }; | |
45 | #else | |
46 | template <typename S, typename = void> | |
47 | struct take_back_impl : take_back_impl<S, when<true>> { }; | |
48 | ||
49 | struct take_back_t { | |
50 | template <typename Xs, typename N> | |
51 | constexpr auto operator()(Xs&& xs, N const& n) const; | |
52 | }; | |
53 | ||
54 | constexpr take_back_t take_back{}; | |
55 | #endif | |
56 | BOOST_HANA_NAMESPACE_END | |
57 | ||
58 | #endif // !BOOST_HANA_FWD_TAKE_BACK_HPP |