Are Tuples as lvalues supposed to be supported?
BCS
ao at pathlink.com
Tue Jul 31 11:13:34 PDT 2007
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.
More information about the Digitalmars-d
mailing list