title: How to properly initialize a boost multi_array of objects?
body: <p>I have been surprised to find that <code>boost::multi_array</code> seems to allocate its initial elements differently from, say, <code>std::vector</code>. It does not seem to fill each element with a unique element (using its default value or default constructor). I'm having trouble finding more information about this.</p>
  
  <p>Is there a way to make the <code>multi_array</code> fill itself with a unique object at each element?</p>
  
  <p>For example, consider the following:</p>
  
  <pre><code>static int num = 0;
  
  struct A {
     int n;
     A() : n((::num)++) {
        std::cout &lt;&lt; "A()" &lt;&lt; std::endl;
     }
     virtual ~A() {}
  
     void print() {
        std::cout &lt;&lt; "n=" &lt;&lt; n &lt;&lt; std::endl;
     }
  };
  
  int main() {
     std::cout &lt;&lt; "vector:" &lt;&lt; std::endl;
     std::vector&lt;A&gt; v(3);
     for (auto x : v) {
        x.print();
     }
  
     std::cout &lt;&lt; "multi:" &lt;&lt; std::endl;
     boost::multi_array&lt;A, 2&gt; m(boost::extents[2][2]);
     for (auto x : m) {
        for (auto y : x) {
           y.print();
        }
     }
  }
  </code></pre>
  
  <p>This results in the output:</p>
  
  <pre><code>vector:
  A()
  A()
  A()
  n=0
  n=1
  n=2
  multi:
  A()
  n=3
  n=3
  n=3
  n=3
  </code></pre>
  
  <p>Why is the constructor called only once for the <code>multi_array</code>? How can the <code>multi_array</code> be "filled out" with unique objects (using <code>A</code>'s default constructor)?</p>