C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Unfair treatment to volatile

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards
View previous topic :: View next topic  
Author Message
Prateek R Karandikar
Guest





PostPosted: Sat May 15, 2004 5:29 pm    Post subject: Unfair treatment to volatile Reply with quote



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 ]

Back to top
Matt Austern
Guest





PostPosted: Sun May 16, 2004 1:31 am    Post subject: Re: Unfair treatment to volatile Reply with quote



[email]kprateek88 (AT) yahoo (DOT) com[/email] (Prateek R Karandikar) writes:

Quote:
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 ]


Back to top
Prateek R Karandikar
Guest





PostPosted: Fri May 21, 2004 4:35 pm    Post subject: Re: Unfair treatment to volatile Reply with quote



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 ]

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language, library and standards All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.