because the back_inserter can’t be created around an Array. So I often end up using std::vector instead of Array, but then I run into problems later when I have to convert one to the other element by element, which seems wasteful. I’m guessing I’m not the only person who struggles with this–it seems like it would be a common problem.
I have two questions:
Is there any way to get JUCE Arrays to work with stl algorithms, ie. some other option to std::back_inserter?
If not, what do people usually do? Abandon stl or find some fancy interface between vectors and Arrays?
Personally, I use std::vector whenever I need to do stuff that requires STL algorithms, or when I just want to iterate over the collection and not do anything fancy with it.
The only times I use juce::Array is when I want to use some of its convenience functions that don’t look as pretty when using STL algorithms, like addIfNotAlreadyThere or removeAllInstancesOf.
So basically, I default to using std::vectors, unless juce::Array makes the code prettier.
For context, in my current project I use std::vector 210 times, juce::Array 6 times and juce::OwnedArray 3 times.
Thanks for the feedback. The thing is, I’m using a lot of other JUCE functions that give me Arrays not vectors, ie. SelectedItemSet and var::getArray(). Still, its good to know that other people approach it this way. For now, building my own iterator as @reuk suggested is definitely the right thing to do. I’m glad that other people here find this “trivial”, because it would have taken me hours!