jimc
September 21, 2016, 10:01am
1
ViewOptions()
{
addAndMakeVisibleComponent(
viewHeader, accountHeader,
colourSaturation, colourSaturationLabel,
passwordEditor, passwordLabel,
usernameEditor,
usernameLabel
);
}
template <typename ComponentType>
void addAndMakeVisibleComponent(ComponentType & comp)
{
addAndMakeVisible(comp);
}
template<typename ComponentType, typename... Args>
void addAndMakeVisibleComponent(ComponentType & comp, Args&... args)
{
addAndMakeVisible(comp);
addAndMakeVisibleComponent(args...);
}
Might be really neat?
jules
September 21, 2016, 10:02am
2
Definitely a good idea - I’d thought of doing the same thing a few times!
jimc
September 21, 2016, 10:03am
3
Not sure that’s a working example, might need some liberal & signs…
jimc
September 21, 2016, 10:05am
4
Fixed. That last & sign was a bitch. Figured it would go after the …!!!
fr810
September 21, 2016, 10:16am
5
What about an initializer_list instead? It might make the code more readable by adding the curly brackets.
jimc
September 21, 2016, 10:17am
6
I can’t seem to find a way of making that work with references. I did try…some hints on stackoverflow that it’s not possible. See if you can do it, I’d be interested!
fr810
September 21, 2016, 10:17am
7
It can’t work with references. Only with pointers, so you would need the ampersand symbol in front of every component… hmmmm
jimc
September 21, 2016, 10:17am
8
Yeah exactly, figured that was way worse ;_)
jimc
September 21, 2016, 10:20am
9
reference_wrapper any use?? And then can you iterate over an initializer list anyway?
lalala
July 23, 2019, 2:01pm
10
what about adding that one :
void addAndMakeVisible (const Array<Component*>& children)
{
for (auto c : children)
addAndMakeVisible (c);
}
There’s a helper method like that in the examples of the tracktion engine and I find it quite useful