IFTI, value types, and top-level const
Jonathan M Davis
jmdavisProg at gmx.com
Fri Jun 7 19:17:49 PDT 2013
On Friday, June 07, 2013 18:43:11 Peter Alexander wrote:
> Ack, it appears it is only done for arrays and pointers :-S
And it pretty much only does that because of all of the issues that const and
immutable strings were giving us with range-based functions. IFTI now
automatically slices arrays, and slices are now tail-const.
Now, we certainly can't strip const in the general case, but I'm inclined to
agree that when the mutable version of the type has no mutable indirections,
stripping const would make sense. However, one problem that I can think of is
that if you're dealing with an rvalue and you don't strip the const, under
some circumstances, you can move the object and avoid a copy altogether, but
if you strip the const, you can't do that or you'd violate the constness of
the object (though maybe you could still get away with it if the type had no
postblit) - and that's problem that doesn't exist in C++, since C++ would
always do the copy. So, I don't know if we can quite get away with stripping
const even if the type has no mutable indirections. It's certainly something
that we should consider though.
- Jonathan M Davis
More information about the Digitalmars-d
mailing list