www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Mixture of type tuple and expression tuple

reply Matthias Walter <xammy xammy.homelinux.net> writes:
Hi,

I'd like to have a function foo which shall depend on several
compile-time expressions (e.g. strings) and gets several arguments whose
types are templatized. Here, "several" means in both cases that the
number of expressions/arguments are to be determined at compile-time.
Here is an example:

foo!("a", "b", c")(42, new MyClass(), 7.0);

At compile-time, some template parameters (strings "a", "b" and "c")
shall be given explicitly and some more template parameters (types of
arguments int, MyClass, double) shall be deduced from the function
arguments.

Is that possible? Of course, I cannot setup two TemplateTupleParameters.

Best regards,

Matthias
Feb 06 2012
next sibling parent Timon Gehr <timon.gehr gmx.ch> writes:
On 02/06/2012 11:26 PM, Matthias Walter wrote:
 Hi,

 I'd like to have a function foo which shall depend on several
 compile-time expressions (e.g. strings) and gets several arguments whose
 types are templatized. Here, "several" means in both cases that the
 number of expressions/arguments are to be determined at compile-time.
 Here is an example:

 foo!("a", "b", c")(42, new MyClass(), 7.0);

 At compile-time, some template parameters (strings "a", "b" and "c")
 shall be given explicitly and some more template parameters (types of
 arguments int, MyClass, double) shall be deduced from the function
 arguments.

 Is that possible? Of course, I cannot setup two TemplateTupleParameters.

 Best regards,

 Matthias

This should do the job: template foo(CompileTimeArgs...){ auto foo(RuntimeArgTypes...)(RuntimeArgTypes args){ ... } } It requires explicit !() in case the CompileTimeArgs tuple is empty. (If that is not what you want, introduce another overload of the template. Eventually, just having alias foo!() foo; will work too, but not currently, because of a compiler bug)
Feb 06 2012
prev sibling parent "Daniel Murphy" <yebblies nospamgmail.com> writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2599

"Matthias Walter" <xammy xammy.homelinux.net> wrote in message 
news:mailman.71.1328567829.20196.digitalmars-d-learn puremagic.com...
 Hi,

 I'd like to have a function foo which shall depend on several
 compile-time expressions (e.g. strings) and gets several arguments whose
 types are templatized. Here, "several" means in both cases that the
 number of expressions/arguments are to be determined at compile-time.
 Here is an example:

 foo!("a", "b", c")(42, new MyClass(), 7.0);

 At compile-time, some template parameters (strings "a", "b" and "c")
 shall be given explicitly and some more template parameters (types of
 arguments int, MyClass, double) shall be deduced from the function
 arguments.

 Is that possible? Of course, I cannot setup two TemplateTupleParameters.

 Best regards,

 Matthias
 

Feb 06 2012