- edited description
Implementing resize() functions for static vectors and matrices
Issue #204
closed
Consider a function which reads a vector from a stream and puts it in a blaze::Vector<>
:
template <typename VT, bool TF>
void readVector(std::istream& is, blaze::Vector<VT, TF>& v)
{
size_t n;
is >> n;
(~v).resize(n);
for (size_t i = 0; i < n; ++i)
is >> (~v)[i];
}
void foo()
{
blaze::DynamicVector<double> v;
readVector(std::cin, v); // OK
blaze::StaticVector<double, 2> v2;
readVector(std::cin, v2); // ERROR: ‘class blaze::StaticVector<double, 2, false>’ has no member named ‘resize’
}
Would it make sense to implement resize()
in static vector and matrix classes in such a way that an exception is thrown if the argument of resize()
does not match the static size? This would avoid the need to implement two versions of the readVector()
function in the example above.
Comments (3)
-
reporter -
reporter I found the
blaze::resize()
function in the documentation, sorry :-) -
reporter - changed status to closed
- Log in to comment