www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - expand variadic template parameters

reply =?UTF-8?B?IkFuZHLDqSI=?= <andre s-e-a-p.de> writes:
Hi,

in this minified example I try to expand the variadic parmaters of
foo to bar:

import std.typecons;

void foo(T ...)(T args)
{
      bar(args.expand);
}

void bar(int i, string s){}

void main()
{
	foo(1, "a");
}

I got the syntax error: no property 'expand' for type '(int,
string)'
I understand args is a TypeTuple and therefore expand is not
working.
Is there a simple way to get it working?

Kind regards
André
Mar 10 2015
next sibling parent ketmar <ketmar ketmar.no-ip.org> writes:
On Tue, 10 Mar 2015 19:11:21 +0000, Andr=C3=A9 wrote:

 Hi,
=20
 in this minified example I try to expand the variadic parmaters of foo
 to bar:
=20
 import std.typecons;
=20
 void foo(T ...)(T args)
 {
       bar(args.expand);
 }
=20
 void bar(int i, string s){}
=20
 void main()
 {
 	foo(1, "a");
 }
=20
 I got the syntax error: no property 'expand' for type '(int, string)'
 I understand args is a TypeTuple and therefore expand is not working.
 Is there a simple way to get it working?
sure. just remove `.expand`. ;-) void foo(T...) (T args) { bar(args); } =
Mar 10 2015
prev sibling next sibling parent reply "Adam D. Ruppe" <destructionator gmail.com> writes:
On Tuesday, 10 March 2015 at 19:11:22 UTC, André wrote:
 Is there a simple way to get it working?
The simplest: just write `bar(args);` - the variadic arguments will automatically expand.
Mar 10 2015
parent =?UTF-8?B?IkFuZHLDqSI=?= <andre s-e-a-p.de> writes:
too many trees in front of my eyes.
Thanks for the answers.

Kind regards
André

On Tuesday, 10 March 2015 at 19:16:23 UTC, Adam D. Ruppe wrote:
 On Tuesday, 10 March 2015 at 19:11:22 UTC, André wrote:
 Is there a simple way to get it working?
The simplest: just write `bar(args);` - the variadic arguments will automatically expand.
Mar 10 2015
prev sibling parent "Meta" <jared771 gmail.com> writes:
On Tuesday, 10 March 2015 at 19:11:22 UTC, André wrote:
 Hi,

 in this minified example I try to expand the variadic parmaters 
 of
 foo to bar:

 import std.typecons;

 void foo(T ...)(T args)
 {
      bar(args.expand);
 }

 void bar(int i, string s){}

 void main()
 {
 	foo(1, "a");
 }

 I got the syntax error: no property 'expand' for type '(int,
 string)'
 I understand args is a TypeTuple and therefore expand is not
 working.
 Is there a simple way to get it working?

 Kind regards
 André
Just to be clear, TypeTuple is a library construct defined in std.typetuple. It doesn't have a .expand member as far as I know. You're probably thinking of tuple.expand. The type of `T ...` is not TypeTuple, but an internal tuple type used by the compiler. TypeTuple is just some syntactic sugar allowing you to create one of these compiler tuples.
Mar 10 2015