Auto keyword with const variable

Artur Skawina art.08.09 at gmail.com
Wed Jul 24 04:25:02 PDT 2013


On 07/24/13 12:54, monarch_dodra wrote:
> On Wednesday, 24 July 2013 at 10:37:40 UTC, Artur Skawina wrote:
>> On 07/24/13 12:09, monarch_dodra wrote:
>>> Keeping it to "same type, 100% of the time" seems like the best.
>>
>> No, it's a design bug. The head qualifier(s) should always be stripped
>> when copying objects. Stripping is always fine (ie safe)
> 
> Nope. Stop. Wrong. Qualification is transitive in D, unlike in C++. Even when copying, stripping qualification is not safe:

"*Head* qualifier(s)". Why do I always end up quoting myself? ;)

Obviously, stripping is only fine for the copied object itself,
not for any internal refs.

   const(int*) cpci;
   auto mpci = cast()cpci;      // const(int)*
   Unqual!(typeof(cpci)) mpci2; // const(int)*

This works already; it's just that having to drop the qualifiers
explicitly is unnecessary and bug-prone (it's too easy to cast away
a bit too much const).

artur


More information about the Digitalmars-d-learn mailing list