gast128 | 20 Aug 10:38
Favicon

multi_array, resize and default constructable

Dear all,

from the documentation I read that if a multi_array is reshaped new elements 
are default constructed:

"Resizing an Array
The boost::multi_array class provides an element-preserving resize operation.
...Any new elements in the array are default constructed..."

It is thus not possible providing a default fill element?
Dr Johann A. Briffa | 21 Aug 10:44
Favicon

Re: multi_array, resize and default constructable

gast128 wrote:
> Dear all,
>
> from the documentation I read that if a multi_array is reshaped new elements 
> are default constructed:
>
> "Resizing an Array
> The boost::multi_array class provides an element-preserving resize operation.
> ...Any new elements in the array are default constructed..."
>
> It is thus not possible providing a default fill element?
>   
The default fill element is the default value of the type. For example, 
if you have a multi_array of doubles, on array construction (or resize) 
all new elements will be 0.0. You cannot change this value without 
changing the default value of the underlying type.
Johann
gast128 | 21 Aug 10:55
Favicon

Re: multi_array, resize and default constructable

Dr Johann A. Briffa <j.briffa <at> ieee.org> writes:

> > ...Any new elements in the array are default constructed..."
> >
> > It is thus not possible providing a default fill element?
> >   
> The default fill element is the default value of the type. For example, 
> if you have a multi_array of doubles, on array construction (or resize) 
> all new elements will be 0.0. You cannot change this value without 
> changing the default value of the underlying type.
> Johann

I understand that, built in types are also defined for default construction.

However I had a need here to override that default. Looking at the 
vector::resize(), it offers an overload function for specifying the fill 
element.

The case I needed was soemthing likea std::pair<HANDLE, nstring>, where the 
the default handle is -1 (i.e. std::pair<HANDLE, nstring> default(-1, ""));. 
Of course this can be solved by promoting this to a full blown struct with 
default ctor, but I donot like to introduce extra structures for just bundling 
data.

Gmane