| 1 | /*! |
| 2 | @file |
| 3 | Forward declares `boost::hana::repeat`. |
| 4 | |
| 5 | Copyright Louis Dionne 2013-2022 |
| 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) |
| 8 | */ |
| 9 | |
| 10 | #ifndef BOOST_HANA_FWD_REPEAT_HPP |
| 11 | #define BOOST_HANA_FWD_REPEAT_HPP |
| 12 | |
| 13 | #include <boost/hana/config.hpp> |
| 14 | #include <boost/hana/core/when.hpp> |
| 15 | |
| 16 | |
| 17 | namespace boost { namespace hana { |
| 18 | //! Invokes a nullary function `n` times. |
| 19 | //! @ingroup group-IntegralConstant |
| 20 | //! |
| 21 | //! Given an `IntegralConstant` `n` and a nullary function `f`, |
| 22 | //! `repeat(n, f)` will call `f` `n` times. In particular, any |
| 23 | //! decent compiler should expand `repeat(n, f)` to |
| 24 | //! @code |
| 25 | //! f(); f(); ... f(); // n times total |
| 26 | //! @endcode |
| 27 | //! |
| 28 | //! |
| 29 | //! @param n |
| 30 | //! An `IntegralConstant` holding a non-negative value representing |
| 31 | //! the number of times `f` should be repeatedly invoked. |
| 32 | //! |
| 33 | //! @param f |
| 34 | //! A function to repeatedly invoke `n` times. `f` is allowed to have |
| 35 | //! side effects. |
| 36 | //! |
| 37 | //! |
| 38 | //! Example |
| 39 | //! ------- |
| 40 | //! @include example/repeat.cpp |
| 41 | #ifdef BOOST_HANA_DOXYGEN_INVOKED |
| 42 | constexpr auto repeat = [](auto const& n, auto&& f) -> void { |
| 43 | f(); f(); ... f(); // n times total |
| 44 | }; |
| 45 | #else |
| 46 | template <typename N, typename = void> |
| 47 | struct repeat_impl : repeat_impl<N, when<true>> { }; |
| 48 | |
| 49 | struct repeat_t { |
| 50 | template <typename N, typename F> |
| 51 | constexpr void operator()(N const& n, F&& f) const; |
| 52 | }; |
| 53 | |
| 54 | BOOST_HANA_INLINE_VARIABLE constexpr repeat_t repeat{}; |
| 55 | #endif |
| 56 | }} // end namespace boost::hana |
| 57 | |
| 58 | #endif // !BOOST_HANA_FWD_REPEAT_HPP |
| 59 | |