www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Are Tuples as lvalues supposed to be supported?

reply Russell Lewis <webmaster villagersonline.com> writes:
I thought that I was supposed to be able to use a Tuple as an lvalue in 
a struct, such as:

   struct Encapsulate(U...) { U val; }

   void Foo(U...)(U args) {
     Encapsulate!(U) temp;
     temp.val = args;
   }

However, when I instantiate Foo, I get the error:
   Error: temp.val is not an lvalue.


So, I looked on the website, and didn't find a statement that I could do 
this.  So I'm asking: is this a 2.0 feature, or is the lack of it a bug?

Russ



P.S. The lack of this is going to make it rather annoying to build a 
Curry() template which takes multiple arguments.  I will have to either 
implement many different Curry templates with different numbers of 
arguments, or else nest them...
Jul 31 2007
parent reply BCS <ao pathlink.com> writes:
Reply to Russell,

 I thought that I was supposed to be able to use a Tuple as an lvalue
 in a struct, such as:
 
 struct Encapsulate(U...) { U val; }
 
 void Foo(U...)(U args) {
 Encapsulate!(U) temp;
 temp.val = args;
 }
 However, when I instantiate Foo, I get the error:
 Error: temp.val is not an lvalue.
 So, I looked on the website, and didn't find a statement that I could
 do this.  So I'm asking: is this a 2.0 feature, or is the lack of it a
 bug?
 
 Russ
 
 P.S. The lack of this is going to make it rather annoying to build a
 Curry() template which takes multiple arguments.  I will have to
 either implement many different Curry templates with different numbers
 of arguments, or else nest them...
 
Do it one part at a time (note that the foreach is unrolled at compile time). struct Encapsulate(U...) { U val; } void Foo(U...)(U args) { Encapsulate!(U) temp; foreach(int i,_;U) temp.val[i] = args[i]; } BTW if you just need a curry template I have a compile time one you might like: http://www.dsource.org/projects/scrapple/browser/trunk/arg_bind/bind.d If you need run time currying I might be able to hack that over lunch.
Jul 31 2007
parent reply BCS <ao pathlink.com> writes:
Reply to Benjamin,

 Reply to Russell,
 
 
 http://www.dsource.org/projects/scrapple/browser/trunk/arg_bind/bind.d
 
 If you need run time currying I might be able to hack that over lunch.
 
done take a look at the unittest to see how it gets used.
Jul 31 2007
parent BCS <ao pathlink.com> writes:
Reply to Benjamin,

 Reply to Benjamin,
 
 Reply to Russell,
 
 http://www.dsource.org/projects/scrapple/browser/trunk/arg_bind/bind.
 d
 
 If you need run time currying I might be able to hack that over
 lunch.
 
done take a look at the unittest to see how it gets used.
Oops, botched the commit, it's there now.
Aug 02 2007