Preview features status?

Tejas notrealemail at gmail.com
Tue Jul 13 15:51:26 UTC 2021


On Wednesday, 19 May 2021 at 08:45:22 UTC, evilrat wrote:
> 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?
> ```

Shouldn't this be a bug? Isn't this still ```const - non-const```?
Do you think this is worth filing?

Also, where did you find out how to represent rvalue references 
as parameters? I couldn't find any info on that. Just learned 
that these are available under a preview switch.


More information about the Digitalmars-d mailing list