How to get indexOf juce::Array<juce::NormalisableRange>

const juce::Array<juce::NormalisableRange<double>> ranges
    juce::NormalisableRange<double> (0.0, 100.0, 0.1),
    juce::NormalisableRange<double> (0.2, 20.0, 0.1),
    juce::NormalisableRange<double> (0.3, 300.0, 0.1),



for (auto& range : ranges)
    const int index { ranges.indexOf (range) }; // always gives an error 

Why can’t I get indexOf from juce::Array<juce::NormalisableRange> ?

Probably because NormalisableRange does not have == operator?

This looks like the issue. @bayu you could define your own equality operator for juce::NormalisableRange<double> and that would probably work, something like:

namespace juce {
inline bool operator== (const juce::NormalisableRange<double>& r1,
                        const juce::NormalisableRange<double>& r2)
    return r1.start == r2.start
        && r1.end == r2.end
        && r1.interval == r2.interval
        && r1.skew == r2.skew
        && r1.symmetricSkew == r2.symmetricSkew;

Although in this particular case, using a range-based for loop over the elements and immediately grabbing the index using indexOf seems like a roundabout way of doing things. You could just use a classic for loop and avoid the indexOf lookup on each iteration:

for (auto index = 0; index < ranges.size(); ++index)
    auto& range = ranges.getReference (index);
1 Like

I’m aware that i could just use classic for loop.

I just thought the function should work OOTB.

Anyway, @connorreviere & @MBO thanks for pointing me to right direction. Thus now i know how to add equality operator when it needed.