Preview features status?
evilrat
evilrat666 at gmail.com
Wed May 19 08:45:22 UTC 2021
On Wednesday, 19 May 2021 at 07:36:53 UTC, evilrat wrote:
>
> -preview=rvaluerefparam
> This one helps with C++ interop where it's the norm but is PITA
> in D.
Well, ok D still got me sometimes even with that preview feature,
this s**t isn't even fun...
```d
// PxVec3 operator-
public PxVec3 opBinary(string op : "-")(ref const(PxVec3) v)
const {
return PxVec3(x - v.x, y - v.y, z - v.z);
}
public float distance(ref const(PxVec3) p) const {
return p.dot(n) + d; // dot is also const
}
// original code, n is plain PxVec3, not const
public PxVec3 project(ref const(PxVec3) p) const {
return p - n * distance(p); // error
}
```
> Error: incompatible types for `(p) -
> (this.n.opBinary(this.distance(p)))`: `const(PxVec3)` and
> `PxVec3`
```d
// lets try this
public PxVec3 project(ref const(PxVec3) p) const {
PxVec3 t = p;
return t - n * distance(t); // error
}
```
> Error: incompatible types for `(t) -
> (this.n.opBinary(this.distance(t)))`: both operands are of type
> `PxVec3`
```d
// ok, no error
public PxVec3 project(ref const(PxVec3) p) const {
auto t = n * distance(p);
pragma(msg, typeof(t)); // PxVec3
return p - t; //
}
U MAD BRO?
```
More information about the Digitalmars-d
mailing list