This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: bounds checking in bitset.


On Fri, 3 Feb 2006, Paolo Carlini wrote:

BHARAT JOSHI wrote:

The bounds checking/exceptions in bitset does not seem to work. I used
gcc 3.4.2 on a FC3 system and also gcc 4.0.0 on a FC4.
this snippet compiles (and runs) with no warnings with -W and -Wall
options enabled.

bitset<9> n;
n[15]=1;    //works
for (i=0 to 20) printf ("%d\n", int(n[i]));  //all 0's excepet in 15th
postition

Maybe your doubt stems from expections pre-DR 11. In the current standard, C++03, operator[] does *not* throw and requires a valid position (user responsability). See 23.3.5.2/46-47, 49-50.

though this is true of standard containers, its not the case for bitset. by standard
"The subscript operator throws out_of_range if subscript is out of
range. There is *no* unchecked subscript operation."


--
Bharat Joshi
Home: http://students.iiit.ac.in/~bharatj


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]