3 Defines `boost::hana::repeat`.
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)
10 #ifndef BOOST_HANA_REPEAT_HPP
11 #define BOOST_HANA_REPEAT_HPP
13 #include <boost/hana/fwd/repeat.hpp>
15 #include <boost/hana/concept/integral_constant.hpp>
16 #include <boost/hana/config.hpp>
17 #include <boost/hana/core/dispatch.hpp>
23 BOOST_HANA_NAMESPACE_BEGIN
24 template <typename I, bool condition>
25 struct repeat_impl<I, when<condition>> : default_ {
26 template <typename F, std::size_t ...i>
27 static constexpr void repeat_helper(F&& f, std::index_sequence<i...>) {
28 using Swallow = std::size_t[];
29 (void)Swallow{0, ((void)f(), i)...};
32 template <typename N, typename F>
33 static constexpr auto apply(N const&, F&& f) {
34 static_assert(N::value >= 0, "hana::repeat(n, f) requires 'n' to be non-negative");
35 constexpr std::size_t n = N::value;
36 repeat_helper(static_cast<F&&>(f), std::make_index_sequence<n>{});
41 template <typename N, typename F>
42 constexpr void repeat_t::operator()(N const& n, F&& f) const {
43 using I = typename hana::tag_of<N>::type;
44 using Repeat = BOOST_HANA_DISPATCH_IF(repeat_impl<I>,
45 hana::IntegralConstant<I>::value
48 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
49 static_assert(hana::IntegralConstant<I>::value,
50 "hana::repeat(n, f) requires 'n' to be an IntegralConstant");
53 return Repeat::apply(n, static_cast<F&&>(f));
56 BOOST_HANA_NAMESPACE_END
58 #endif // !BOOST_HANA_REPEAT_HPP