This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Template to map an array into a vector/matrix

Tags: None
(comma "," separated)
kde-renorm
Registered Member
Posts
9
Karma
0
I am having trouble implementing the following function template to map an array into a vector/matrix.

Code: Select all
template <typename T>
unspecified_return_type get_vector_map(T* buf, size_t n);

template <typename T>
unspecified_return_type get_matrix_map(T* buf, size_t cols, size_t rows);


Type T can be any floating point or integer numeric type, optionally const qualified.
Is there a way to do it a without writing a lot of boiler plate code?

Thank you.
User avatar
ggael
Moderator
Posts
3447
Karma
19
OS
Something like this should do the job:
Code: Select all
template<typename T> Map<Matrix<T,Dynamic,1> >
get_vector_map(T* buf, size_t n) { return Matrix<T,Dynamic,1>::Map(buf,n); }

template<typename T> Map<const Matrix<T,Dynamic,1> >
get_vector_map(const T* buf, size_t n) { return Matrix<T,Dynamic,1>::Map(buf,n); }
kde-renorm
Registered Member
Posts
9
Karma
0
Thanks. It worked.


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Google [Bot], Yahoo [Bot]