Motive behind !empty() with front() instead of Optional front()
Paul Backus
snarwin at gmail.com
Wed Apr 7 21:44:52 UTC 2021
On Wednesday, 7 April 2021 at 21:31:38 UTC, Q. Schroll wrote:
> Template type deduction alone (C++ has 4 different rule sets
> about type deduction) is complicated. One reason for stripping
> `ref` from the argument types unless they explicitly bind to
> `ref` parameters is that references should act like aliases:
> ```C++
> int i;
> int& r = i;
> f(i);
> f(r);
> ```
> Here, `f(r)` should act the same as `f(i)` irrespective of how
> `f` is defined. `f` could take `int`, `int&`, `const int&`, or
> `T`, `const T&`, or `T&&` for some `T` that can implicitly
> constructed from `int`. For `int&&` or `T&`it wouldn't compile.
> References as type constructors are weird.
References as type constructors are weird *in C++* because of
specific choices made by the designers of C++ (such as:
"references should act like aliases"). There is nothing inherent
to the concept of a reference type that implies this kind of
weirdness. D does not have to make the same choices as C++, and
`ref(T)` in D does not have to suffer from the issues that
references suffer from in C++.
More information about the Digitalmars-d
mailing list