Boost logo

Ublas :

Subject: Re: [ublas] bounded_matrix declaration only
From: Vardan Akopian (vakopian_at_[hidden])
Date: 2008-11-15 17:11:46


On Sat, Nov 15, 2008 at 7:00 AM, Moritz Beber
<moritz.beber_at_[hidden]> wrote:
> Dear members,
> I'm trying to use the bounded_matrix as a member variable for a class
> I'm currently designing. The declaration of it gives me troubles though
> since the way I'm currently approaching it, it would require size
> information for the declaration already while I naturally only have that
> information available at the point of construction of an object of that
> class. A default constructor where that info is not available yet is
> another story also.
> I suppose I could use a normal matrix but since the size of the matrix
> will not change at all during the existence time of the class object I
> thought a bounded_matrix would make sense.
>
> So the code I had in mind would look somewhat like this:
>
> myclass {
> bounded_matrix<double, M, N, column_major> m;
> ...
> }
>
> myclass::myclass(unsigned int rows, unsigned int cols)
> {
> m = bounded_matrix<double, rows, cols, column_major>(rows, cols);
> ...
> }
>
> Is there a way to bypass the need to give specific size information at
> the time of declaration?
>
> Thank you for your insights,
> Moritz
>
> _______________________________________________
> ublas mailing list
> ublas_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/ublas
>

Moritz,

Template parameters have to be known at compile time.
Just because the matrix size does not change during its existence,
does not mean that it is known at compile time. So your code above
cannot work with bounded_matrix. You either need to use
unbounded_matrix, or you'd need to make your class a template class as
well. The latter only moves the issue to another place (where you'd
need to instantiate myclass), so if in principle the dimensions are
not known at compile time, this solution will not work and you'd still
have to go with unbounded_matrix.

Hope it helps
-Vardan