On 9/20/13 10:52 AM, Jonathan M Davis wrote:
On Friday, September 20, 2013 10:47:15 Andrei Alexandrescu wrote:
On 9/20/13 10:02 AM, Szymon Gatner wrote:
On Friday, 20 September 2013 at 16:57:43 UTC, Jonathan M Davis wrote:
If an object is const, then all of its members are const, which means
that any
ranges you get from its members will be const, making such ranges
useless.
That is so weird to hear considering I added ranges to my C++ code and
my Vector<T>::all() const can easily return non-const range even tho
container is itself const. This kinda looks like D is more limited in
that area than C++... Or I really am not getting something.
Yah, it should be possible for a const container to offer ranges over
its (non-modifiable) elements.
That's probably easy to do if the container is well-written, because the
container creates the range. The problem is converting a const range to tail
const one, which is what you have to do if you ever end up with a const range
for any reason, and if you're using const much, that's trivial to do
(especially if you ever have a range as a member variable). Unfortunately, in
practice, that conversion is quite difficult to do with user-defined types even
though it works just fine with arrays.
I'm not sure such a conversion is needed all that often.
Andrei