tuple sumlimation
Pragma
ericanderton at yahoo.removeme.com
Fri Feb 16 14:29:37 PST 2007
Bill Baxter wrote:
> Pragma wrote:
>> Kevin Bealer wrote:
>>> Currently, Tuples are sublimated into argument lists. What do people
>>> think of using an operator (say, *) to prevent this? The reason I
>>> ask is that the current technique makes it hard to pass multiple
>>> tuples on the same function call.
>>>
>>> I think it's not absolutely required; currently you can pass the
>>> tuple lengths, let the tuples melt together, and then split them with
>>> slicing.
>>>
>>> Kevin
>>
>> The only workaround I have used for this is to turn a tuple into a
>> compile-time "struct" to pass it to another template:
>>
>> import std.metastrings;
>>
>> // use whatever name you want, and add whatever 'member' aliases you
>> need here
>> template Struct(V...){
>> alias V Values;
>> }
>>
>> template MyExample(alias Arr1,alias Arr2){
>> pragma(msg,Format!("%s",Arr1.Values[0]));
>> pragma(msg,Format!("%s",Arr2.Values[0]));
>> }
>>
>> alias MyExample!(Struct!(1,2,3),Struct!("x","y","z")) Foobar;
>
> Nice idea! But do you mean
>
> struct Struct(V...) {
> alias V Values;
> }
> ??? Otherwise Struct is just making a Tuple. Or is the trick the fact
> that you pass it as an alias to the template that needs two Tuples?
Yes. The trick is indeed the use of "alias"; it allows you to pass the template's namespace just as you would any other
instanced type. AFAIK, you can't just pass a tuple to an alias param, so you need to wrap it first.
--
- EricAnderton at yahoo
More information about the Digitalmars-d
mailing list