My template tuple code does not compile

H. S. Teoh hsteoh at quickfur.ath.cx
Tue Feb 26 23:21:32 UTC 2019


On Tue, Feb 26, 2019 at 10:56:37PM +0000, Victor Porton via Digitalmars-d-learn wrote:
[...]
> After fixing the error you pointed me, it does not work too:
> 
> mixin ProviderParams!("S", ((int, "x"), (float, "y")));

Try this:

	mixin ProviderParams!("S", int, "x", float, "y");


> Also: Can I nevertheless group arguments?

Template argument lists auto-expand, so even if you could group
arguments, they make no functional difference.  If you truly need to
distinguish between groups of arguments, you have to pack them into a
non-autoexpanding group, for example:

	template Group(Args...) {
		// Note: NOT eponymous.
		alias contents = Args;
	}

	mixin ProviderParams!("S", Group!(int, "x"), Group!(float, "y"));

Keep in mind, however, that inside ProviderParams you will need to
explicitly access .contents. For example:

	mixin template ProviderParams(Args...) {
		static foreach (arg; Args[1 .. $]) {{
			alias type = arg.contents[0];
			alias name = arg.contents[1];
		}}
	}


T

-- 
Prosperity breeds contempt, and poverty breeds consent. -- Suck.com


More information about the Digitalmars-d-learn mailing list