Make dsp::ProcessorChain compatible with structured binding

I just tried it out here, supplying these two simple template specialisation makes a juce::dsp::ProcessorChain is compatible with C++ 17 structured binding

namespace std
template <typename... Processors>
struct tuple_size<::juce::dsp::ProcessorChain<Processors...>>
    static constexpr size_t value = sizeof... (Processors);

template <size_t Index, typename... Processors>
struct tuple_element<Index, ::juce::dsp::ProcessorChain<Processors...>>
        : tuple_element<Index, tuple<Processors...>>


Now you can write something like e.g.

juce::dsp::ProcessorChain<juce::dsp::Gain<float>, juce::dsp::IIR::Filter<float>> chain;

auto& [gain, filter] = chain;

gain.setGainDecibels (-3.0f);
*filter.coefficients = someCoeffs;

which is just super beautiful and verbose from my point of view :heart_eyes: What do you think?

This is a really nice idea, I’ll take a look at adding it. Thanks!


How does this line of code work?
Where can I read more about this syntax?

This should give you a good overview:

It’s basically a new convenient language feature, introduced with C++ 17


Thanks for your patience, this is now available on develop:

I’m closing this thread to free spent votes.

1 Like