tuples and freeze dried function args

Bill Baxter dnewsgroup at billbaxter.com
Fri Feb 23 10:28:39 PST 2007


torhu wrote:
> I have a function like this:
> 
> void f(int, int, int);
> 
> 
> I know that I can do this:
> 
> template Tuple(T...)
> {
>     alias T Tuple;
> }
> 
> alias Tuple!(1, 2, 3) args;
> 
> 
> And this now works:
> 
> f(args);
> 
> 
> But I want to go one step further, and store the args somehow.
> 
> alias Tuple!(1, 2, 3) OneSetOfArgs;
> alias Tuple!(4, 5, 6) AnotherSetOfArgs;
> 
> 
> If I have
> 
> struct S { */ ...  */};
> 
> 
> can I somehow store OneSetOfArgs in a field, so I can do this?
> 
> S s;
> 
> s.args = OneSetOfArgs;
> 
> f(s.args);  // s.args expands into three ints
> 
> 
> I take it the answer is 'no'?
> 
> Solutions involving wrapping f, or using assembly is not really what I'm 
> looking for.

I think you may be able to get something like what you want using type 
tuples and tupleof.

alias Tuple!(int,int,int) FArgs;
struct S
{
    FArgs OneSetOfArgs;
    FArgs OtherSetOfArgs;
}
S s;
Foo(s.OneSetOfArgs.tupleof);

Or something along those lines maybe?

--bb


More information about the Digitalmars-d-learn mailing list