Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
constexpr_utils.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cstddef>
4#include <tuple>
5#include <utility>
6
7namespace bb {
8namespace detail {
9
13template <size_t Min, size_t Max, size_t Inc> constexpr auto make_index_range()
14{
15 static_assert(Max >= Min);
16 static_assert(Inc >= 1);
17 return []<size_t... Is>(std::index_sequence<Is...>) {
18 return std::index_sequence<Min + (Is * Inc)...>{};
19 }(std::make_index_sequence<(Max - Min - 1) / Inc + 1>{});
20}
21
22} // namespace detail
23
71template <size_t Start, size_t End, size_t Inc, class F> constexpr void constexpr_for(F&& f)
72{
73 // F must be a template lambda with a single **typed** template parameter that represents the iterator
74 // (e.g. [&]<size_t i>(){ ... } is good)
75 // (and [&]<typename i>(){ ... } won't compile!)
76 constexpr auto indices = detail::make_index_range<Start, End, Inc>();
77 [&]<size_t... Is>(std::index_sequence<Is...>) { (f.template operator()<Is>(), ...); }(indices);
78}
79
80}; // namespace bb
constexpr auto make_index_range()
Create an index sequence from Min to Max (not included) with an increment of Inc.
Entry point for Barretenberg command-line interface.
constexpr void constexpr_for(F &&f)
Implements a loop using a compile-time iterator. Requires c++20. Implementation (and description) fro...
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
Definition tuple.hpp:13