]>
Commit | Line | Data |
---|---|---|
b32b8144 FG |
1 | // Copyright Louis Dionne 2013-2017 |
2 | // Copyright Jason Rice 2017 | |
3 | // Distributed under the Boost Software License, Version 1.0. | |
4 | // (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) | |
5 | ||
6 | #ifndef TEST_SUPPORT_COUNTER_HPP | |
7 | #define TEST_SUPPORT_COUNTER_HPP | |
8 | ||
9 | #include <boost/hana/fwd/at.hpp> | |
10 | #include <boost/hana/fwd/concept/iterable.hpp> | |
11 | #include <boost/hana/fwd/drop_front.hpp> | |
12 | #include <boost/hana/fwd/is_empty.hpp> | |
13 | #include <boost/hana/integral_constant.hpp> | |
14 | ||
15 | ||
16 | // Counter - an infinite iterable for the masses | |
17 | ||
18 | struct Counter_tag { }; | |
19 | ||
20 | template <std::size_t N = 0> | |
21 | struct Counter { | |
22 | using hana_tag = Counter_tag; | |
23 | static constexpr std::size_t value = N; | |
24 | }; | |
25 | ||
26 | ||
27 | namespace boost { namespace hana { | |
28 | ////////////////////////////////////////////////////////////////////////// | |
29 | // Iterable | |
30 | ////////////////////////////////////////////////////////////////////////// | |
31 | template <> | |
32 | struct at_impl<Counter_tag> { | |
33 | template <typename T, typename N> | |
34 | static constexpr decltype(auto) apply(T, N) { | |
35 | return hana::size_c<T::value + N::value>; | |
36 | } | |
37 | }; | |
38 | ||
39 | template <> | |
40 | struct drop_front_impl<Counter_tag> { | |
41 | template <typename T, typename N> | |
42 | static constexpr auto apply(T, N) { | |
43 | return Counter<T::value + N::value>{}; | |
44 | } | |
45 | }; | |
46 | ||
47 | template <> | |
48 | struct is_empty_impl<Counter_tag> { | |
49 | template <typename Xs> | |
50 | static constexpr auto apply(Xs) | |
51 | -> hana::false_ | |
52 | { return {}; } | |
53 | }; | |
54 | }} // end namespace boost::hana | |
55 | ||
56 | #endif // !TEST_SUPPORT_COUNTER_HPP |