#ifndef CK_FUNCTIONAL2_HPP #define CK_FUNCTIONAL2_HPP #include "functional.hpp" #include "Sequence.hpp" namespace ck { template struct static_for_impl; template struct static_for_impl> { template __host__ __device__ constexpr void operator()(F f) const { swallow{(f(Number{}), 0)...}; } }; // F signature: F(Number) template struct static_for { template __host__ __device__ constexpr void operator()(F f) const { static_assert(NBegin <= NEnd, "wrongs! should have NBegin <= NEnd"); static_assert((NEnd - NBegin) % Increment == 0, "Wrong! should satisfy (NEnd - NBegin) % Increment == 0"); static_for_impl::type>{}(f); } }; template struct lambda_accumulate_on_sequence { const Reduce& f; index_t& result; __host__ __device__ constexpr lambda_accumulate_on_sequence(const Reduce& f_, index_t& result_) : f(f_), result(result_) { } template __host__ __device__ constexpr index_t operator()(IDim) const { return result = f(result, Seq::Get(IDim{})); } }; template __host__ __device__ constexpr index_t accumulate_on_sequence(Seq, Reduce f, Number /*initial_value*/) { index_t result = Init; static_for<0, Seq::mSize, 1>{}(lambda_accumulate_on_sequence(f, result)); return result; } } // namespace ck #endif