addAndMakeVisible with variable number of arguments?

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?

Definitely a good idea - I’d thought of doing the same thing a few times!

Not sure that’s a working example, might need some liberal & signs…

Fixed. That last & sign was a bitch. Figured it would go after the …!!!

What about an initializer_list instead? It might make the code more readable by adding the curly brackets.

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!

It can’t work with references. Only with pointers, so you would need the ampersand symbol in front of every component… hmmmm

Yeah exactly, figured that was way worse ;_)

reference_wrapper any use?? And then can you iterate over an initializer list anyway?

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