template in struct

Philippe Sigaud philippe.sigaud at gmail.com
Sat Mar 23 11:20:30 PDT 2013


On Sat, Mar 23, 2013 at 6:08 PM, dsmith <dsmith at nomail.com> wrote:
> How to make workable something like this:
>
> struct S (T...) {
>   T args;
>   string arg_str;
>
>   foreach(i; args) {
>     arg_str ~ to!string(i);
>   }
> }
>
> void some_function(S s) {   // here ... Error: struct S(T...) is used as a
> type
>   s.args = [a, b, c];
>   string args = s.arg_str;
> }

S is not a type here, but a template name. The type is S!(SomeArgs).
That's what you should pass to some_function:

void some_function(Args...)(S!(Args) s)
{
    s.args = [a, b, c];
    string args = s.arg_str;
}


More information about the Digitalmars-d-learn mailing list