Why does this work?
h_zet via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Jun 23 19:27:13 PDT 2014
On Monday, 23 June 2014 at 09:09:56 UTC, hane wrote:
> On Monday, 23 June 2014 at 08:30:44 UTC, h_zet wrote:
>> import std.typecons;
>>
>> auto foo2(R)(R foopara){
>> return tuple(foopara, is(R==int));
>> }
>>
>> void main(){
>> auto tuple(a,b) = foo2(1);
>> }
>>
>>
>> I'm expecting some error such as can not act as left value but
>> when I compiled this, no error occured. DMD version is DMD64
>> v2.065.(ldc2 exited with error function declaration without
>> return type)
>>
>> Why does this work? Or it is a bug?
>
> You declared a variable template named "tuple" (with unused
> type parameters a, b) on that line.
> http://dlang.org/template.html#variable-template
>
> I think this is very confusable syntax...
>
> void main()
> {
> auto tuple(a, b) = foo2(1);
>
> writeln(tuple!(int, int)); // writes "Tuple!(int, bool)(1,
> true)"
>
> tuple!(int, int) = foo2(20);
> writeln(tuple!(int, int)); // writes "Tuple!(int, bool)(20,
> true)"
>
> }
Problem solved, Thank you so much!
More information about the Digitalmars-d-learn
mailing list