/*! @file Defines `boost::hana::repeat`. @copyright Louis Dionne 2013-2016 Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt) */ #ifndef BOOST_HANA_REPEAT_HPP #define BOOST_HANA_REPEAT_HPP #include #include #include #include #include #include BOOST_HANA_NAMESPACE_BEGIN template struct repeat_impl> : default_ { template static constexpr void repeat_helper(F&& f, std::index_sequence) { using Swallow = std::size_t[]; (void)Swallow{0, ((void)f(), i)...}; } template static constexpr auto apply(N const&, F&& f) { static_assert(N::value >= 0, "hana::repeat(n, f) requires 'n' to be non-negative"); constexpr std::size_t n = N::value; repeat_helper(static_cast(f), std::make_index_sequence{}); } }; //! @cond template constexpr void repeat_t::operator()(N const& n, F&& f) const { using I = typename hana::tag_of::type; using Repeat = BOOST_HANA_DISPATCH_IF(repeat_impl, hana::IntegralConstant::value ); #ifndef BOOST_HANA_CONFIG_DISABLE_CONCEPT_CHECKS static_assert(hana::IntegralConstant::value, "hana::repeat(n, f) requires 'n' to be an IntegralConstant"); #endif return Repeat::apply(n, static_cast(f)); } //! @endcond BOOST_HANA_NAMESPACE_END #endif // !BOOST_HANA_REPEAT_HPP