Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.
Container code snippet that converts a std::vector<std::vector<X> > to std::vector<std::vector<Y> > using static_cast.
* View the code of 'ConvertMatrix' in plain text
//From http://www.richelbilderbeek.nl/CppConvertMatrix.htm
template <class Source, class Target>
const std::vector<std::vector<Target> > ConvertMatrix(
const std::vector<std::vector<Source> >& v)
{
const int maxy = static_cast<int>(v.size());
assert(maxy>0);
const int maxx = static_cast<int>(v[0].size());
std::vector<std::vector<Target> > t(maxy, std::vector<Target>(maxx));
{
{
t[y][x] = static_cast<Target>(v[y][x]);
}
}
return t;
}
Go back to Richel Bilderbeek's C++ page.
Go back to Richel Bilderbeek's homepage.