• Docs >
  • Program Listing for File unrolled_for_impl_.hpp
Shortcuts

Program Listing for File unrolled_for_impl_.hpp

Return to documentation for file (include/ripple/algorithm/detail/unrolled_for_impl_.hpp)

#ifndef RIPPLE_ALGORITHM_UNROLLED_FOR_IMPL_HPP
#define RIPPLE_ALGORITHM_UNROLLED_FOR_IMPL_HPP

#include <ripple/utility/forward.hpp>
#include <ripple/utility/number.hpp>

namespace ripple::detail {

template <size_t Amount>
struct Unroll : public Unroll<(Amount <= 1 ? 0 : Amount - 1)> {
  static constexpr size_t previous_level = Amount <= 1 ? 0 : Amount - 1;

  using PreviousLevel = Unroll<previous_level>;

  template <typename Functor, typename... Args>
  ripple_all constexpr Unroll(
    Functor&& functor, Args&&... args) noexcept
  : PreviousLevel{ripple_forward(functor), ripple_forward(args)...} {
    functor(Num<previous_level>(), ripple_forward(args)...);
  }
};

template <>
struct Unroll<1> {
  template <typename Functor, typename... Args>
  ripple_all constexpr Unroll(
    Functor&& functor, Args&&... args) noexcept {
    functor(Num<0>(), ripple_forward(args)...);
  }
};

template <>
struct Unroll<0> {
  template <typename Functor, typename... Args>
  ripple_all constexpr Unroll(
    Functor&& functor, Args&&... args) noexcept {}
};

} // namespace ripple::detail

#endif // RIPPLE_ALGORITHM_UNROLLED_FOR_HPP

Docs

Access comprehensive developer documentation for Ripple

View Docs

Tutorials

Get tutorials to help with understand all features

View Tutorials

Examples

Find examples to help get started

View Examples