cxx11_maxsizevector.cpp
Go to the documentation of this file.
1 #include "main.h"
2 
3 #include <exception> // std::exception
4 
5 #include <unsupported/Eigen/CXX11/Tensor>
6 
7 struct Foo
8 {
9  static Index object_count;
10  static Index object_limit;
12 
13  Foo(int x=0) : dummy(x)
14  {
15 #ifdef EIGEN_EXCEPTIONS
16  // TODO: Is this the correct way to handle this?
17  if (Foo::object_count > Foo::object_limit) { std::cout << "\nThrow!\n"; throw Foo::Fail(); }
18 #endif
19  std::cout << '+';
21  eigen_assert((internal::UIntPtr(this) & (127)) == 0);
22  }
23  Foo(const Foo&)
24  {
25  std::cout << 'c';
27  eigen_assert((internal::UIntPtr(this) & (127)) == 0);
28  }
29 
30  ~Foo()
31  {
32  std::cout << '~';
34  }
35 
36  class Fail : public std::exception {};
37 };
38 
41 
42 
43 
44 EIGEN_DECLARE_TEST(cxx11_maxsizevector)
45 {
48  for(int r = 0; r < g_repeat; r++) {
49  Index rows = internal::random<Index>(3,30);
50  Foo::object_limit = internal::random<Index>(0, rows - 2);
51  std::cout << "object_limit = " << Foo::object_limit << std::endl;
52  bool exception_raised = false;
53 #ifdef EIGEN_EXCEPTIONS
54  try
55  {
56 #endif
57  std::cout << "\nVectorX m(" << rows << ");\n";
58  VectorX vect(rows);
59  for(int i=0; i<rows; ++i)
60  vect.push_back(Foo());
61 #ifdef EIGEN_EXCEPTIONS
62  VERIFY(false); // not reached if exceptions are enabled
63  }
64  catch (const Foo::Fail&) { exception_raised = true; }
65  VERIFY(exception_raised);
66 #endif
68 
69  {
70  Foo::object_limit = rows+1;
71  VectorX vect2(rows, Foo());
73  }
75  std::cout << '\n';
76  }
77 }
Matrix< Scalar, Dynamic, 1 > VectorX
Definition: sparse_lu.cpp:41
Foo()
Definition: ctorleak.cpp:11
Foo(const Foo &)
static Index object_limit
Definition: ctorleak.cpp:8
static Index object_count
Definition: ctorleak.cpp:7
std::size_t UIntPtr
Definition: Meta.h:92
#define VERIFY_IS_EQUAL(a, b)
Definition: main.h:386
static int g_repeat
Definition: main.h:169
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index
The Index type as used for the API.
Definition: Meta.h:74
#define eigen_assert(x)
Definition: Macros.h:1037
EIGEN_ALIGN_TO_BOUNDARY(128) int dummy
#define VERIFY(a)
Definition: main.h:380
int dummy
Definition: ctorleak.cpp:9
The MaxSizeVector class.
Definition: MaxSizeVector.h:31
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
EIGEN_DECLARE_TEST(cxx11_maxsizevector)


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:34:06