Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:43:39

0001 /*!
0002 @file
0003 Defines `boost::hana::repeat`.
0004 
0005 Copyright Louis Dionne 2013-2022
0006 Distributed under the Boost Software License, Version 1.0.
0007 (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
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     //! @cond
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     //! @endcond
0056 }} // end namespace boost::hana
0057 
0058 #endif // !BOOST_HANA_REPEAT_HPP