D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 4918 - tuples in eponymous template have default values only
Summary: tuples in eponymous template have default values only
Status: RESOLVED WORKSFORME
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 normal
Assignee: No Owner
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-09-23 01:10 UTC by Jonathan M Davis
Modified: 2015-06-09 05:14 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Jonathan M Davis 2010-09-23 01:10:49 UTC
This code

import std.stdio;
import std.typecons;

template mytemp(T...)
{
    static if(T.length == 1)
        enum mytemp = tuple(T[0]);
    else
        enum mytemp = tuple(T[0], mytemp!(T[1..$]).expand);
}

void main()
{
    writeln(mytemp!(5));
    writeln(mytemp!(5, 10, 7));
    writeln(mytemp!(true));
    writeln(mytemp!(true, false, true));
    writeln(mytemp!("hello"));
    writeln(mytemp!("hello", "world"));
}


results in this output

Tuple!(int)(0)
Tuple!(int,int,int)(0, 0, 0)
Tuple!(bool)(false)
Tuple!(bool,bool,bool)(false, false, false)
Tuple!(string)()
Tuple!(string,string)(, )


If I change it to

import std.stdio;
import std.typecons;

template mytemp(T...)
{
    enum mytemp = T[0];
}

void main()
{
    writeln(mytemp!(5));
    writeln(mytemp!(true));
    writeln(mytemp!("hello"));
}


I get

5
true
hello


So obviously, there's something wrong with tuple here. And it's pretty crippling for my current project actually.
Comment 1 yebblies 2012-02-14 08:18:56 UTC
Seem to work with dmd 2.058