I'm trying to implement a templated function that takes as argument either a std::vector<float>&
or a std::vector<std::vector<float>>
. Below a simplified version of my code.
I'm getting errors like:
C2440 'initializing' cannot convert from initializer list
when I tried to implement this when calling function PlotDataset()
.
What is the best/cleanest way to achieve this?
template<typename T>
plot(T& y)
{
// depending on whether T is a float or a std::vector<float>,
// I want to set my for loop differently
if(std::is_same<T, std::vector<std::vector<float>>>::value)
{
for(size_t n{0}; n < y.size(); n++)
{
// axes is a shared_ptr, while PlotDataset is a class constructor
// taking a std::vector<float> as argument
axes->addDataset(PlotDataset(y.at(n)));
}
}
else if(std::is_same<T, std::vector<float>>::value)
{
axes->addDataset(PlotDataset(y))
}
}