Boost logo

Ublas :

Subject: Re: [ublas] Why is there no constructor taking an initial value?
From: Karl Meerbergen (karl.meerbergen_at_[hidden])
Date: 2009-01-24 12:13:08

Thorsten Ottosen wrote:
> Gunter Winkler skrev:
>> Am Donnerstag, 22. Januar 2009 16:13 schrieb Thorsten Ottosen:
>>> Hi,
>>> I was a bit surprised that there is no way to fill a
>>> triangular_matrix with a default value. Say, I would have expected
>>> this to work:
>>> triangular_matrix<double> m(42,42,42);
>>> Is there any reason why this constructor is not provided?
>> because it is not needed:
>> // untested
>> triangular_matrix<double,lower> m((
>> triangular_adaptor<lower>(scalar_matrix<double>(42,42,42))));
> Right. I do something similar to get a zero matrix. But that syntax is
> *so* verbose. Normal STL containers has this type of constructor, and
> so users expect it to be provided.
> -Thorsten

I think a special constructor is not needed. It is not because STL
containers have such constructors that other packages should follow the
same ideas. I would suggest a function fill(a, value) which is much
clearer than a constructor with three arguments. Such function could be
used to fill any ublas mutable object. STL's solution
std::fill(a.begin(), a.end(), value ) is not elegant either.