Imported Upstream version 1.64.0
[platform/upstream/boost.git] / boost / hana / fwd / take_front.hpp
1 /*!
2 @file
3 Forward declares `boost::hana::take_front` and `boost::hana::take_front_c`.
4
5 @copyright Louis Dionne 2013-2017
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_FRONT_HPP
11 #define BOOST_HANA_FWD_TAKE_FRONT_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 first `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_front(xs, n)`
25     //! is a new sequence containing the first `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_front.cpp
41 #ifdef BOOST_HANA_DOXYGEN_INVOKED
42     constexpr auto take_front = [](auto&& xs, auto const& n) {
43         return tag-dispatched;
44     };
45 #else
46     template <typename S, typename = void>
47     struct take_front_impl : take_front_impl<S, when<true>> { };
48
49     struct take_front_t {
50         template <typename Xs, typename N>
51         constexpr auto operator()(Xs&& xs, N const& n) const;
52     };
53
54     constexpr take_front_t take_front{};
55 #endif
56
57     //! Equivalent to `take_front`; provided for convenience.
58     //! @ingroup group-Sequence
59     //!
60     //!
61     //! Example
62     //! -------
63     //! @include example/take_front_c.cpp
64 #ifdef BOOST_HANA_DOXYGEN_INVOKED
65     template <std::size_t n>
66     constexpr auto take_front_c = [](auto&& xs) {
67         return hana::take_front(forwarded(xs), hana::size_c<n>);
68     };
69 #else
70     template <std::size_t n>
71     struct take_front_c_t;
72
73     template <std::size_t n>
74     constexpr take_front_c_t<n> take_front_c{};
75 #endif
76 BOOST_HANA_NAMESPACE_END
77
78 #endif // !BOOST_HANA_FWD_TAKE_FRONT_HPP