C++ UFCS update

Ola Fosheim Grøstad via Digitalmars-d digitalmars-d at puremagic.com
Wed Feb 24 02:03:19 PST 2016


On Wednesday, 24 February 2016 at 07:25:13 UTC, Dominikus Dittes 
Scherkl wrote:
> stdout << "double value is: " << i<<1;
>
> Oops.

error: invalid operands of types '_IO_FILE*' and 'const char 
[18]' to binary 'operator<<'

> This happens, and you won't notice until someone complains 
> about the wrong value in the output.

Only a neophyte would make such a mistake. Thanks to the messy 
precedence for operators in C you always have to be careful with 
parentheses.

> in D neither ! nor ~ is "reused". They are both unary operators 
> in C. D only defined new binary operators which use the same 
> characters, but there is no way to confuse them.

I am used to D-advocates blindly defending any position, but 
claiming that symbols aren't reused in D isn't a position I would 
expect anyone to defend. Unary or binary is not the issue.

if(!a!(c,!d)(!e)){...}
a~=3;
b=~3;

> On the other side having two different "piplining" operators 
> "." and "->" makes refactoring the code an ugly mess: If you 
> decided to use a reference parameter instead of a pointer you 
> have to replace all "->" by ".". But oops, there is still a 
> pointer within the referenced struct?

In C++ I typically use "&" or "&&" references instead of 
pointers. In D's "Unique" you get weak duck-typing where you risk 
accessing a member of Unique instead of the object.

However for C++ smart pointers you generally use "->" so you get 
strong typing.




More information about the Digitalmars-d mailing list