Const template

Frits van Bommel fvbommel at REMwOVExCAPSs.nl
Tue Jan 23 10:41:37 PST 2007


Andrei Alexandrescu (See Website For Email) wrote:
> Frits van Bommel wrote:
>> Deletion of a const reference will be necessary for const objects at 
>> the very least (since there are no non-const references to them). 
>> Presumably, that's what the "const destructor" is for.
>>
>> A case could be made for disallowing explicit deletion of const 
>> references, but that would mean const objects would only be deletable 
>> by the GC. That, in turn would mean const objects would be unusable by 
>> people who need (or just prefer) the GC to be disabled...
>> Perhaps this should be more of a "best practice" instead of a language 
>> rule?
> 
> Deletion of pointers to const data has always been a sticky issue in 
> C++. There are good arguments either way. I think it should be 
> disallowed, otherwise a caller passing a const class object does not 
> have a guarantee that the callee didn't mutate the object, which is the 
> very purpose of the entire scaffolding.

But as I mentioned, there will only be const references to const 
instances, so that would mean const objects couldn't be explicitly deleted.
And there are people who prefer or need to work with GC off. This 
limitation would deny them the use of const objects (unless they like 
memory leaks ;) ).

For that reason, I think it should maybe merely be very rude to delete a 
const reference unless you are absolutely sure nobody else has a 
reference to the object (that they will ever use), not an error.



More information about the Digitalmars-d mailing list