Thread overview | ||||||
---|---|---|---|---|---|---|
|
January 12, 2011 Using template typetuples? | ||||
---|---|---|---|---|
| ||||
The language documentation covers some basic uses of TypeTuples in templates, but nothing about using them with classes. I would like a template class, which essentially wraps a function, which has template parameters for return value and template tuple arguments. However, what if I want to convert a TypeTuple of int, double, string to its respective Function-wrapped TypeTuple, i.e. Function!int, Function!double, Function!string. Is there any way to do so? |
January 12, 2011 Re: Using template typetuples? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean Eskapp | Sean Eskapp <eatingstaples@gmail.com> wrote: > The language documentation covers some basic uses of TypeTuples in templates, > but nothing about using them with classes. I would like a template class, > which essentially wraps a function, which has template parameters for return > value and template tuple arguments. > > However, what if I want to convert a TypeTuple of int, double, string to its > respective Function-wrapped TypeTuple, i.e. Function!int, Function!double, > Function!string. Is there any way to do so? std.typetuple has staticMap, which sounds like what you want: alias TypeTuple!( int, double, string ) tup; alias staticMap!( Function, tup ) functions; Is this what you want? -- Simen |
January 12, 2011 Re: Using template typetuples? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Simen kjaeraas | That looks like it.. only, it's not working: void main() { TypeTuple!(int, int) foo; foo[0] = 1; foo[1] = 2; double MakeStuff(in int bar) { return cast(double)bar; } auto foobar = staticMap!(MakeStuff)(foo); } This fails compilation with the error "Error: function expected before (), not () of type ()" |
January 12, 2011 Re: Using template typetuples? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Sean Eskapp | Nevermind, I see my error. Thank you! |
Copyright © 1999-2021 by the D Language Foundation