1 // -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- 2 // vi: set et ts=4 sw=2 sts=2: 3 #ifdef HAVE_CONFIG_H 4 #include "config.h" 5 #endif 6 7 #include <iostream> 8 #include <algorithm> 9 10 #include <dune/common/densevector.hh> 11 #include <dune/common/exceptions.hh> 12 13 class MyVector; 14 15 namespace Dune 16 { 17 template< > 18 struct DenseMatVecTraits< MyVector > 19 { 20 typedef MyVector derived_type; 21 typedef double value_type; 22 typedef unsigned int size_type; 23 }; 24 } 25 26 class MyVector : public Dune::DenseVector< MyVector > 27 { 28 public: MyVector(unsigned int size,double v=0)29 MyVector ( unsigned int size, double v = 0 ) 30 : data_( size, v ) {} 31 size() const32 unsigned int size () const { return data_.size(); } 33 operator [](unsigned int i)34 double& operator[] ( unsigned int i ) { return data_[ i ]; } operator [](unsigned int i) const35 const double& operator[] ( unsigned int i ) const { return data_[ i ]; } 36 protected: 37 std::vector< double > data_; 38 }; 39 40 main()41int main() 42 { 43 try 44 { 45 unsigned int n = 15; 46 MyVector v( n, 1 ); 47 if( ( v.end() - v.begin() ) < 0 ) 48 DUNE_THROW(Dune::Exception, "Negative value reported for end() - begin()" ); 49 50 return 0; 51 } catch (Dune::Exception& e) { 52 std::cerr << e << std::endl; 53 return 1; 54 } catch (...) { 55 std::cerr << "Generic exception!" << std::endl; 56 return 2; 57 } 58 } 59