This is the mail archive of the libstdc++@sourceware.cygnus.com 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]

Why does vector<>::at() throw range_error?



#include <vector>
  using std::vector;

#include <iostream>
  using std::cout;

#include <stdexcept>
  using std::exception;

#include <typeinfo> 

int main(void)
{
  vector<int> v(10);
  try
  {
    v.at(v.size()+1)=0;
  }
  catch(exception& e)
  {
    cout << "Caught " << typeid(e).name() << " .\n";
  }

}

/*
  This program, when compiled with gcc 2.95.2 and linked against a jan
    24 cvs checkout of libstdc++, or libstdc++-2.90.7, shows that
    vector<>::at() throws std::range_error:
    
$g++ -g -Wall -O2 -I/usr/local/libstdc++-cvs/include/g++-v3/  -L/usr/local/libstdc++-cvs/lib vector_at.cc
$a.out
Caught 11range_error .

  However, 23.1.1 paragraph 13 says:
  # ... at() throws out_of_range if n>= a.size() .

  Is this a bug? What is the difference between out_of_range and
    range_error? 

 */


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