Boost logo

Ublas :

From: Gunter Winkler (guwi17_at_[hidden])
Date: 2008-02-12 12:56:52


Am Dienstag, 12. Februar 2008 16:06 schrieb Hongyu Miao:
> try
> {
>         myvector.resize(blocksize);
> }
> catch(std::bad_alloc& e)
> {
>         std::cerr << e.what() << '\n';
>         return EXIT_FAILURE;
> }

Yes, see below:

#include <boost/numeric/ublas/vector.hpp>
#include <iostream>

using namespace boost::numeric::ublas;

int main(int argc, char * argv[]) {
  vector<double> myvector;
  try
    {
      myvector.resize((std::size_t) -1UL);
    }
  catch(std::bad_alloc& e)
    {
      std::cerr << e.what() << '\n';
      return EXIT_FAILURE;
    }
}

output:
$ g++ -I $HOME/include memtest.cpp -o memtest
$ ./memtest
St9bad_alloc

mfg
Gunter