1typedef Matrix<float,1,Dynamic> MatrixType; 2typedef Map<MatrixType> MapType; 3typedef Map<const MatrixType> MapTypeConst; // a read-only map 4const int n_dims = 5; 5 6MatrixType m1(n_dims), m2(n_dims); 7m1.setRandom(); 8m2.setRandom(); 9float *p = &m2(0); // get the address storing the data for m2 10MapType m2map(p,m2.size()); // m2map shares data with m2 11MapTypeConst m2mapconst(p,m2.size()); // a read-only accessor for m2 12 13cout << "m1: " << m1 << endl; 14cout << "m2: " << m2 << endl; 15cout << "Squared euclidean distance: " << (m1-m2).squaredNorm() << endl; 16cout << "Squared euclidean distance, using map: " << 17 (m1-m2map).squaredNorm() << endl; 18m2map(3) = 7; // this will change m2, since they share the same array 19cout << "Updated m2: " << m2 << endl; 20cout << "m2 coefficient 2, constant accessor: " << m2mapconst(2) << endl; 21/* m2mapconst(2) = 5; */ // this yields a compile-time error 22