Topic: Unfair treatment to volatile
Author: kprateek88@yahoo.com (Prateek R Karandikar)
Date: Fri, 21 May 2004 16:35:13 +0000 (UTC) Raw View
Most of the language rules relate to cv-qualifiers, and not const and
volatile individually. Shouldn't the standard library reflect that?
Maybe we could have a new syntax for declaring the 4 versions at one
go. Also why const_cast? Wouldn't cv_cast be more appropriate?
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
To iterate is human, to recurse divine.
-L. Peter Deutsch
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: kprateek88@yahoo.com (Prateek R Karandikar)
Date: Sat, 15 May 2004 17:29:51 +0000 (UTC) Raw View
At many places in the standard library, there are 2 versions of
things: const and non-const. For example, pointer and const_pointer,
reference operator[](size_type); and const_reference
operator[](size_type) const;, etc. Why aren't there 4 versions:
un-cv-qualified,
const,
volatile, and
const volatile?
Although const is used much more that volatile, I don't think that can
that be the reason???
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: austern@well.com (Matt Austern)
Date: Sun, 16 May 2004 01:31:32 +0000 (UTC) Raw View
kprateek88@yahoo.com (Prateek R Karandikar) writes:
> At many places in the standard library, there are 2 versions of
> things: const and non-const. For example, pointer and const_pointer,
> reference operator[](size_type); and const_reference
> operator[](size_type) const;, etc. Why aren't there 4 versions:
>
> un-cv-qualified,
> const,
> volatile, and
> const volatile?
>
> Although const is used much more that volatile, I don't think that can
> that be the reason???
Nevertheless, that is the reason. We need
const T& std::vector<T>::operator[](size_t) const;
because it's useful. People want to have const
vectors and they want to look at the objects in them.
A vector class without a const overload of operator[]
would not be a useful vector class.
The same is not true of volatile. I've heard a few
people over the years note the lack of symmetry between
const and volatile, but I have never once heard anyone
say that they have an application where it's necessary
for them to write
volatile std::vector<int> v;
volatile int& x;
...
v[17] = x;
If things like that ever do become important, then we
can revisit the question of whether we need to work on
making the library "volatile correct". Until then,
there just doesn't seem to be a compelling need to do
that analysis and to double the number of member
functions.
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]