From 666ade0c9384aee1d35fe48a837d6de4d175f7c9 Mon Sep 17 00:00:00 2001 From: Gael Guennebaud Date: Mon, 9 Feb 2009 09:54:48 +0000 Subject: [PATCH] add "remap" snippet using placement new --- Eigen/src/Core/Map.h | 8 +++++++- doc/snippets/Map_placement_new.cpp | 5 +++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 doc/snippets/Map_placement_new.cpp diff --git a/Eigen/src/Core/Map.h b/Eigen/src/Core/Map.h index 5fe13005f..4c2c455ce 100644 --- a/Eigen/src/Core/Map.h +++ b/Eigen/src/Core/Map.h @@ -39,6 +39,12 @@ * This class represents a matrix or vector expression mapping an existing array of data. * It can be used to let Eigen interface without any overhead with non-Eigen data structures, * such as plain C arrays or structures from other libraries. + * + * \b Tips: to change the array of data mapped by a Map object, you can use the C++ + * placement new syntax: + * + * Example: \include Map_placement_new.cpp + * Output: \verbinclude Map_placement_new.out * * This class is the return type of Matrix::Map() but can also be used directly. * @@ -79,7 +85,7 @@ template class Map inline Map(const Scalar* data, int size) : Base(data, size) {} inline Map(const Scalar* data, int rows, int cols) : Base(data, rows, cols) {} - + inline void resize(int rows, int cols) { EIGEN_ONLY_USED_FOR_DEBUG(rows); diff --git a/doc/snippets/Map_placement_new.cpp b/doc/snippets/Map_placement_new.cpp new file mode 100644 index 000000000..2e40eca32 --- /dev/null +++ b/doc/snippets/Map_placement_new.cpp @@ -0,0 +1,5 @@ +int data[] = {1,2,3,4,5,6,7,8,9}; +Map v(data,4); +cout << "The mapped vector v is: " << v << "\n"; +new (&v) Map(data+4,5); +cout << "Now v is: " << v << "\n"; \ No newline at end of file