Boost logo

Ublas :

From: Neal Becker (ndbecker2_at_[hidden])
Date: 2007-04-06 06:44:11


Now that we seem to have addressed optionally bypassing constructors of
elements, it seems that the resize operation is a bit confused. As I see
it, there are 3 dimensions to resize options:

1) preserve?
2) construct elements?
3) if construct, use default value or supplied value?

I think ideally these 3 options should be orthogonal. Unfortunately, the
present interfaces presented by vector.hpp and storage.hpp don't support
that.

I think the best compromise is simply to add this to vector.hpp:

        BOOST_UBLAS_INLINE
        void resize (size_type size, value_type const& init) {
          data ().resize (size, init);
        }

This allows a resize to specify an init value for new elements. It
unfortunately forces preserve, but I believe most use cases in which init
is specified would want preserve anyway.