Opened 10 years ago

Last modified 9 years ago

#6889 new Feature Requests

Initialise multi_array with a given value

Reported by: Andrew Morris <andy@…> Owned by: Ronald Garcia
Milestone: To Be Determined Component: multi_array
Version: Boost 1.49.0 Severity: Problem
Keywords: Cc:

Description

The multi-array only allows users to initialise all elements to a default constructed T(). That may not be desirable if you would like a different value, either for performance reasons or because the type does not support default initialisation. For example:

#include <vector>
#include <boost/multi_array.hpp>

struct no_default
{
    explicit no_default(int i) {}
};

int main()
{
    std::vector<no_default> v(10, no_default(3));
    boost::multi_array<no_default, 3> m(boost::extents[10][10][10]); // won't compile
}

Offering constructors that accept a value to be used to initialise the elements would be the easiest fix. This would also align with std::vector usage.

Attachments (1)

multi_array_accept_initial_value.diff (8.8 KB ) - added by Andrew Morris <andy@…> 10 years ago.
Proposed change

Download all attachments as: .zip

Change History (3)

by Andrew Morris <andy@…>, 10 years ago

Proposed change

comment:1 by rodrigo.benenson@…, 9 years ago

Any update on this issue ?

in reply to:  1 comment:2 by andy@…, 9 years ago

Replying to rodrigo.benenson@…:

Any update on this issue ?

Not to my knowledge. I don't know if I was supposed to have emailed someone with the request or anything, though - I just created this ticket, uploaded the change and that was it.

Note: See TracTickets for help on using tickets.