Iterating through a dsp::ProcessorChain

is there a way to iterate through a dsp::ProcessorChain with a ton of processors in it? doing something like:

for (auto i = 0; i < 100; ++i)

doesn’t work (i’m guessing because of the templated function call of get< >() ), and i’m wondering if there’s some other way to go about it

thanks for any help!

edit: am i just better off sticking them all in some array and iterating through them that way?

Something like this would let you iterate all the processors in the chain:

namespace detail
    template <std::size_t... Index, typename Chain, typename Fn>
    constexpr void forEach (std::index_sequence<Index...>, Chain& chain, Fn&& fn)
        (fn (chain.template get<int (Index)>()), ...);

template <typename... Ts, typename Fn>
constexpr void forEach (ProcessorChain<Ts...>& chain, Fn&& fn)
    detail::forEach (std::index_sequence_for<Ts...>{},
                     std::forward<Fn> (fn));

If you want to access both the processor and the index of the processor, you could change the body of the helper to something like:

        (fn (chain.template get<int (Index)>(), Index), ...);
1 Like