]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /*! |
2 | @file | |
3 | Defines `boost::hana::detail::variadic::take`. | |
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_DETAIL_VARIADIC_TAKE_HPP | |
11 | #define BOOST_HANA_DETAIL_VARIADIC_TAKE_HPP | |
12 | ||
13 | #include <boost/hana/config.hpp> | |
14 | #include <boost/hana/detail/variadic/split_at.hpp> | |
15 | #include <boost/hana/functional/always.hpp> | |
16 | #include <boost/hana/functional/reverse_partial.hpp> | |
17 | ||
18 | #include <cstddef> | |
19 | ||
20 | ||
21 | BOOST_HANA_NAMESPACE_BEGIN namespace detail { namespace variadic { | |
22 | struct take_impl2 { | |
23 | template <typename F, typename ...Xs> | |
24 | constexpr decltype(auto) operator()(F&& f, Xs&& ...xs) const { | |
25 | return static_cast<F&&>(f)(static_cast<Xs&&>(xs)...); | |
26 | } | |
27 | }; | |
28 | ||
29 | struct take_impl1 { | |
30 | template <typename ...Xs> | |
31 | constexpr auto operator()(Xs&& ...xs) const { | |
32 | return hana::always( | |
33 | reverse_partial(take_impl2{}, | |
34 | static_cast<Xs&&>(xs)...) | |
35 | ); | |
36 | } | |
37 | }; | |
38 | ||
39 | template <std::size_t n> | |
40 | struct take_t { | |
41 | template <typename ...Xs> | |
42 | constexpr decltype(auto) operator()(Xs&& ...xs) const { | |
43 | return variadic::split_at<n>(static_cast<Xs&&>(xs)...)(take_impl1{}); | |
44 | } | |
45 | }; | |
46 | ||
47 | template <std::size_t n> | |
48 | constexpr take_t<n> take{}; | |
49 | }} BOOST_HANA_NAMESPACE_END | |
50 | ||
51 | #endif // !BOOST_HANA_DETAIL_VARIADIC_TAKE_HPP |