Boost logo

Ublas :

From: Ian McCulloch (ianmcc_at_[hidden])
Date: 2005-01-25 08:04:14


Gunter Winkler wrote:

[...]

> We already discussed this issue at the developer meeting. We finally
> decided to use value_type(0) because value_type could be a big algebraic
> object, e.g. a matrix. For matrices there is a big difference between
> allocating an empty matrix using the default constructor and allocating a
> matrix full of zeroes using the "int" constructor.

Sorry, I didn't read this right the first time. Why would the "int"
constructor allocate a matrix full of zeroes? How would it get the size
information? What could the "int" ctor for a matrix do differently to the
default ctor?

I thought the reason why value_type() not preferred was that someone had
some examples of user-types for which the default ctor didn't initialize to
logical zero? I think that is reasonable. But value_type(0) will cause
problems I think. Consider

struct SymbolicValue
{
   SymbolicValue(std::string const& Value) : Value_(Value) {}
   SymbolicValue(char const* Value) : Value_(Value) {}

   // operator=, +=, +, -, ...

   std::string Value_;
};

int main()
{
   ublas::matrix<SymbolicValue> M(10,10); // oops!
}

Cheers,
Ian