Motive behind !empty() with front() instead of Optional front()

Paul Backus snarwin at gmail.com
Fri Apr 9 21:17:03 UTC 2021


On Friday, 9 April 2021 at 20:40:54 UTC, Q. Schroll wrote:
>
> As Andrei said, in C++, apart from the `decltype` exception 
> (which is justified), references behave as aliases. In D, it's 
> the same, apart from `__trais(isRef)` which is also justified. 
> What else do you expect from a reference object? Maybe I'm 
> biased, but I don't see how other solutions than C++'s would be 
> better.

Hypothetically, if `ref` were a type qualifier, I'd expect it to 
behave the same way as D's other type qualifiers. We don't strip 
`const` or `shared` from types during template instantiation (the 
special case of `const(T[])` → `const(T)[]` notwithstanding), so 
my baseline expectation is that we wouldn't strip `ref` either.

Maybe there's an argument to be made that this is a bad idea, and 
that you should always be able to replace an lvalue with a 
reference without any effect on the program's behavior. But I 
don't think you can take it as given that that's *obviously* the 
correct way to do references, just because that's what C++ does.


More information about the Digitalmars-d mailing list