aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Gael Guennebaud <g.gael@free.fr>2009-02-09 09:54:48 +0000
committerGravatar Gael Guennebaud <g.gael@free.fr>2009-02-09 09:54:48 +0000
commit666ade0c9384aee1d35fe48a837d6de4d175f7c9 (patch)
tree7bec9bdb2f2eb5db4f98d93fab74ef3c428d73a5
parent5b4c3b21f30231d5a9526d79396752057cb5cfd2 (diff)
add "remap" snippet using placement new
-rw-r--r--Eigen/src/Core/Map.h8
-rw-r--r--doc/snippets/Map_placement_new.cpp5
2 files changed, 12 insertions, 1 deletions
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<typename MatrixType, int PacketAccess> 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<RowVectorXi> v(data,4);
+cout << "The mapped vector v is: " << v << "\n";
+new (&v) Map<RowVectorXi>(data+4,5);
+cout << "Now v is: " << v << "\n"; \ No newline at end of file