repeat.hpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*!
  2. @file
  3. Forward declares `boost::hana::repeat`.
  4. @copyright Louis Dionne 2013-2017
  5. Distributed under the Boost Software License, Version 1.0.
  6. (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
  7. */
  8. #ifndef BOOST_HANA_FWD_REPEAT_HPP
  9. #define BOOST_HANA_FWD_REPEAT_HPP
  10. #include <boost/hana/config.hpp>
  11. #include <boost/hana/core/when.hpp>
  12. BOOST_HANA_NAMESPACE_BEGIN
  13. //! Invokes a nullary function `n` times.
  14. //! @ingroup group-IntegralConstant
  15. //!
  16. //! Given an `IntegralConstant` `n` and a nullary function `f`,
  17. //! `repeat(n, f)` will call `f` `n` times. In particular, any
  18. //! decent compiler should expand `repeat(n, f)` to
  19. //! @code
  20. //! f(); f(); ... f(); // n times total
  21. //! @endcode
  22. //!
  23. //!
  24. //! @param n
  25. //! An `IntegralConstant` holding a non-negative value representing
  26. //! the number of times `f` should be repeatedly invoked.
  27. //!
  28. //! @param f
  29. //! A function to repeatedly invoke `n` times. `f` is allowed to have
  30. //! side effects.
  31. //!
  32. //!
  33. //! Example
  34. //! -------
  35. //! @include example/repeat.cpp
  36. #ifdef BOOST_HANA_DOXYGEN_INVOKED
  37. constexpr auto repeat = [](auto const& n, auto&& f) -> void {
  38. f(); f(); ... f(); // n times total
  39. };
  40. #else
  41. template <typename N, typename = void>
  42. struct repeat_impl : repeat_impl<N, when<true>> { };
  43. struct repeat_t {
  44. template <typename N, typename F>
  45. constexpr void operator()(N const& n, F&& f) const;
  46. };
  47. constexpr repeat_t repeat{};
  48. #endif
  49. BOOST_HANA_NAMESPACE_END
  50. #endif // !BOOST_HANA_FWD_REPEAT_HPP