File indexing completed on 2025-01-30 09:43:39
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef BOOST_HANA_REPEAT_HPP
0011 #define BOOST_HANA_REPEAT_HPP
0012
0013 #include <boost/hana/fwd/repeat.hpp>
0014
0015 #include <boost/hana/concept/integral_constant.hpp>
0016 #include <boost/hana/config.hpp>
0017 #include <boost/hana/core/dispatch.hpp>
0018
0019 #include <cstddef>
0020 #include <utility>
0021
0022
0023 namespace boost { namespace hana {
0024 template <typename I, bool condition>
0025 struct repeat_impl<I, when<condition>> : default_ {
0026 template <typename F, std::size_t ...i>
0027 static constexpr void repeat_helper(F&& f, std::index_sequence<i...>) {
0028 using Swallow = std::size_t[];
0029 (void)Swallow{0, ((void)f(), i)...};
0030 }
0031
0032 template <typename N, typename F>
0033 static constexpr auto apply(N const&, F&& f) {
0034 static_assert(N::value >= 0, "hana::repeat(n, f) requires 'n' to be non-negative");
0035 constexpr std::size_t n = N::value;
0036 repeat_helper(static_cast<F&&>(f), std::make_index_sequence<n>{});
0037 }
0038 };
0039
0040
0041 template <typename N, typename F>
0042 constexpr void repeat_t::operator()(N const& n, F&& f) const {
0043 using I = typename hana::tag_of<N>::type;
0044 using Repeat = BOOST_HANA_DISPATCH_IF(repeat_impl<I>,
0045 hana::IntegralConstant<I>::value
0046 );
0047
0048 #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS
0049 static_assert(hana::IntegralConstant<I>::value,
0050 "hana::repeat(n, f) requires 'n' to be an IntegralConstant");
0051 #endif
0052
0053 return Repeat::apply(n, static_cast<F&&>(f));
0054 }
0055
0056 }}
0057
0058 #endif