On Monday, 29 July 2013 at 14:34:13 UTC, John Colvin wrote:
On Monday, 29 July 2013 at 14:21:45 UTC, JS wrote:
Then a third? The fact whether there is a use case or not, or whether I have one or not should be irrelevant. The issue should stand on it's own. Having some easily way to use multiple variadic parameters is either useful or not.

There are a mind-boggling large number of things that are useful, but that's not the criteria for adding something to a programming language.

A new feature has to be *sufficiently* useful to justify the increased complexity of the language and it's implementations (plus not clashing badly with other features). Example use cases are a useful way of demonstrating just how useful a feature can be.

The need for "grouping variadics" creeps up every now and then, and it *would* be useful to provide support for it. It may seem like there isn't really a need, but it's not like a lot of people do meta programming with recursive variadics. But for those that *do* the requirement is obvious.

That said, it is *far* from requiring a language change.

A simple "Group" struct will solve the problem without a second thought:

struct Group(Args...)
{
    alias Ungroup = Args;
}

So, if we take into account that phobos already has a static if for types (called select), it can become:

//----
void main()
{
    enum a = false;
alias K = Select!(a, Group!(int, 1), Group!(double, 2)).Ungroup;
}
//----

See? There's no need to make such a fuss about this.

"Group", contrary to Tuple, is not meant to ever be instanciated. This makes it better in this scenario, as "Tuple!5" will not compile (how do you construct an instance of type "5")? Another advantage is that "Group" is an explicit type, which means you can for a template that doesn't have "alias" parameters to accpet values. EG:
Select!(cond, 1, 2);// This doesn't compile
Select!(a, Group!(1), Group!(2)).Ungroup; //But this does :)

It's a bit hackish, but it saves your butt.

The "issue" (I think) is that we don't have "Group" in phobos, forcing our users (eg. JS), to re-invent and re-write the wheel, over and over again, which is not great.


Placing this right under TypeTuple in std.typetuple seems ideal? Should I submit a pull/ER ?

Reply via email to