digitalmars.D.learn - Using opOpAssign, cannot assign sequence
- Alex (13/13) Apr 05 2019 class X(T)
- Alex (4/16) Apr 05 2019 I was thinking using tuple would work(of course is longer than
- ag0aep6g (17/20) Apr 05 2019 `tuple` works for me:
- Paul Backus (4/12) Apr 05 2019 Works for me if you make opOpAssign a variadic template:
class X(T)
void opOpAssign(string op)(T d)
If T has more than length of one then
x += ????
We can work around this but it seems to me that we should be able
to get it to work in some way
x += Alias!(a,b,c)
fails to package it up as do all other things I have tried.
void Add(Ts d) { opOpAssign!("+")(d); }
Then x.Add(a,b,c) works fine.
But of course defeats the entire purpose of opOpAssigns short
hand notation.
Apr 05 2019
On Friday, 5 April 2019 at 13:59:27 UTC, Alex wrote:
class X(T)
void opOpAssign(string op)(T d)
If T has more than length of one then
x += ????
We can work around this but it seems to me that we should be
able to get it to work in some way
x += Alias!(a,b,c)
fails to package it up as do all other things I have tried.
void Add(Ts d) { opOpAssign!("+")(d); }
Then x.Add(a,b,c) works fine.
But of course defeats the entire purpose of opOpAssigns short
hand notation.
I was thinking using tuple would work(of course is longer than
Add but would allow for a more general approach, it would require
automatic unpacking though and so doesn't work.
Apr 05 2019
On 05.04.19 16:00, Alex wrote:I was thinking using tuple would work(of course is longer than Add but would allow for a more general approach, it would require automatic unpacking though and so doesn't work.`tuple` works for me: ---- import std.typecons: tuple; class X(T ...) { void opOpAssign(string op)(T d) {} } void main() { auto x = new X!(int, float, string); int a = 42; float b = 4.2; string c = "foo"; x += tuple(a, b, c); } ----
Apr 05 2019
On Friday, 5 April 2019 at 13:59:27 UTC, Alex wrote:class X(T) void opOpAssign(string op)(T d) If T has more than length of one then x += ???? We can work around this but it seems to me that we should be able to get it to work in some way x += Alias!(a,b,c) fails to package it up as do all other things I have tried.Works for me if you make opOpAssign a variadic template: void opOpAssign(string op, Args...)(Args args) Full example: https://run.dlang.io/is/dPk3BN
Apr 05 2019









ag0aep6g <anonymous example.com> 