digitalmars.D.learn - opOpAssign
- Nicholas Wilson (46/46) Jul 08 2016 struct Pointer(uint p, T) if(p <= Generic)
- ketmar (1/1) Jul 08 2016 auto opOpAssign(string op)(ptrdiff_t i) if(op =="+" || op == "-")
- Nicholas Wilson (2/4) Jul 08 2016 Derp. Thanks!
struct Pointer(uint p, T) if(p <= Generic) { T* ptr; ref T opUnary(string op)() if(op=="*") { return *ptr; } ref T opIndex(size_t i) { return *(ptr+i); } auto opBinary(string op)(ptrdiff_t i) if(op == "+" || op == "-") { return Pointer!(p, T) (mixin("ptr" ~ op ~ "i")); } auto opOpAssign(string op)(ptrdiff_t i) if(op =="+=" || op == "-=") { //mixin("ptr"~op~"i;"); ptr += i; } } void main() { int a = void; alias fooint = Pointer!(2,int); auto b = fooint(&a); auto c = *b; *b = 42; b[0] = 7; auto e = b + 5; auto f = b - 4; auto g = &a; g += 3; b += 7; b -= 9; } errors with pointer.d(23): Error: 'b += 7' is not a scalar, it is a Pointer!(2u, int) pointer.d(24): Error: 'b -= 9' is not a scalar, it is a Pointer!(2u, int) irrespective of the presence or absence of the opOpAssign method or its definition. surely this should work. What am I doing wrong?
Jul 08 2016
auto opOpAssign(string op)(ptrdiff_t i) if(op =="+" || op == "-")
Jul 08 2016
On Friday, 8 July 2016 at 07:15:06 UTC, ketmar wrote:auto opOpAssign(string op)(ptrdiff_t i) if(op =="+" || op == "-")Derp. Thanks!
Jul 08 2016