Boost logo

Boost Users :

Subject: [Boost-users] [multi-array] Is default initialization guaranteed?
From: Eugenio Bargiacchi (svalorzen_at_[hidden])
Date: 2014-03-15 17:30:49


Hello,
I'm trying to figure out whether boost::multi_array does guarantee any
initialization on its elements, since I can't find an explicit mention of
this in the docs. I've noticed that all constructors of boost_multi array
call the function allocate_space(), which is defined as follows:

    void allocate_space() {
      typename Allocator::const_pointer no_hint=0;
      base_ = allocator_.allocate(this->num_elements(),no_hint);
      this->set_base_ptr(base_);
      allocated_elements_ = this->num_elements();
      std::uninitialized_fill_n(base_,allocated_elements_,T());
    }

Thus, std::uninitialized_fill_n should set all values to their default
ones, right? For example, a boost::multi_array containing doubles is
guaranteed to be zeroed at constructions, am I correct?

Or are there cases where there's no guarantee of initialization, and that
is why the documentation does not mention it?

Thanks in advance.

Best regards,
Eugenio Bargiacchi



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net