2

std::vector<T> foo(100) initialises every element with the default value for T. Does boost::multi_array<T, 2> foo(boost::extents[10][10]) do the same?

1 Answer 1

1

It does, using std::allocator::construct() by default.

Sign up to request clarification or add additional context in comments.

1 Comment

That is right, and construct calls new(p) U(); which initializes to zero even for trivial types. I think this choice is a mistake for trivial types for performance and debuggability reasons (it is not possible to detect initialized memory because of this forced initialization).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.