I am using different types of data : say double *, double **, Eigen::Matrix< Index, Eigen::Dynamic, Eigen::Dynamic >, std::vector ...
I am using different codes, and they mix those types, so I would like to avoid copies of datas when passing from one type to another, e.g. say I have double * positions, and in another part of code I need std::vector vectorOfPositions, and I would like to avoid costly initialiazation of vectorOfPositions... Similarly, Eigen with the method Map, seems to offer a solution. I wonder if there is a general way of doing so ...
So thanks a lot for for the help. This std::span solution is attractive but the primary design of the algorithms I am using is not mine.
Some examples of the codes I was refering to :
typedef Eigen::Matrix<double,3,1> Vec3x;
typedef std::vector<Vec3xArray, Eigen::aligned_allocator<Vec3x> Vec3xArray;
typedef std::vector<Eigen::Vector3d> line;
struct point { double x; double y; double z;};
typedef struct point point;
point* m_points;
std::vector<double> m_positions;
Vec3xArray vertices;
line m_line;
Partial answer for std::vector< Type > to Type* : "The elements are stored contiguously, which means that elements can be accessed not only through iterators, but also using offsets to regular pointers to elements. This means that a pointer to an element of a vector may be passed to any function that expects a pointer to an element of an array." ref. here.
Partial answer for Type* to std::vector : std::vector assumes ownership of the data -> this is not possible !
With Eigen, use the Map method to initialize, and data() to get a pointer to the data. See Eigen doc.
std::variantorstd::any