Boost logo

Boost :

From: jhrwalter (walter_at_[hidden])
Date: 2001-12-12 05:20:46


--- In boost_at_y..., Peter Schmitteckert (boost) <boost_at_s...> wrote:
> Salut,
>
> On Tuesday 11 December 2001 11:14, you wrote:
>
> > > > of containers (e.g. vector<vector<> >) or as an mapping to an
1-D
> > > > storage container (e.g. matrix (i, j) == vector (i * size2 +
j)).
> > > >
> > > > In the former case we should define capacity1()/capacity2() to
> >
> > return
> >
> > > > the number of allocated rows/columns, in the latter we should
> >
> > define
> >
> > > > capacity() to return the number of allocated elements in the
1-D
> > > > storage container.
> > >
> > > So, matrix_range<matrix<T> > allows for reshaping, not just
> > > creating sub-matrix views ?
> >
> > No, (efficient) reshape could be an option for matrix types,
which
> > use an 1-D array as storage.
> >
>
> Then I don't understand, why capacity1()/capacity2() is non-generic,
> since I'm not allowed to make use of capacity() in a sense, that I
> reshape the matrix, so capacity() is useless and we have
> capacity1()/capacity2() only.

Let's take examples:
 
Case 1: the storage for the first matrix type is an 1-D array, i.e. m
(i, j) = a [i * size + j]. Then client code could perform something
like the following operation with capacity():
 
if (new_size1 * new_size2 <= m.capacity ())
    m.resize (new_size1, new_size2);
else
    std::cout << "oops: reallocation necessary" << std::endl;
 
Case 2: the storage for the next matrix type is a 2-D array, i.e. m
(i, j) = a [i] [j]. Then client code could perform the following
operation with capacity1()/capacity2():
 
if (new_size1 <= m.capacity1 () && new_size2 <= m.capacity2 ()) {
    m.resize (new_size1, new_size2);
else
    std::cout << "oops: reallocation necessary" << std::endl;
 
Regards
 
Joerg


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk