c++ - Efficient way to convert/reinterpret vector<T> as vector<array<T, 1>> -
i want call method (template) takes vector<array<t, n>>&
result method returns vector<t>
is there efficient (o(1)) way reinterpret vector<t>
vector<array<t,1>>
? possible / safe reinterpret_cast
it?
if t
std::array<u,1>
you should able template deduction , overloading:
template <typename t> std::vector<t> myfunc() { return {t{1}}; } template <typename t> void myotherfunc(std::vector<t>) { cout << "not array\n"; } template <typename t, size_t n> void myotherfunc(std::vector<std::array<t,n>>) { cout << "an array\n"; }
then calling this:
myotherfunc(myfunc<int>()); //prints "not array" myotherfunc(myfunc<std::array<int,1>>()); //prints "an array"
Comments
Post a Comment