title: How to construct std::array object with initializer list?
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/5549524/how-do-i-initialize-a-member-array-with-an-initializer-list">How do I initialize a member array with an initializer_list?</a>  </p>
  </blockquote>
  
  
  
  <p>You can construct an std::array just fine with an initializer list: </p>
  
  <pre><code>std::array&lt;int, 3&gt; a = {1, 2, 3};  // works fine
  </code></pre>
  
  <p>However, when I try to construct it from an <code>std::initializer_list</code> as a data member or base object in a class, it doesn't work:</p>
  
  <pre><code>#include &lt;array&gt;
  #include &lt;initializer_list&gt;
  
  template &lt;typename T, std::size_t size, typename EnumT&gt;
  struct enum_addressable_array : public std::array&lt;T, size&gt;
  {
      typedef std::array&lt;T, size&gt; base_t;
      typedef typename base_t::reference reference;
      typedef typename base_t::const_reference const_reference;
      typedef typename base_t::size_type size_type;
  
      enum_addressable_array(std::initializer_list&lt;T&gt; il) : base_t{il} {}
  
      reference operator[](EnumT n)
      {
          return base_t::operator[](static_cast&lt;size_type&gt;(n));
      }
  
      const_reference operator[](EnumT n) const
      {
          return base_t::operator[](static_cast&lt;size_type&gt;(n));
      }
  };
  
  enum class E {a, b, c};
  enum_addressable_array&lt;char, 3, E&gt; ea = {'a', 'b', 'c'};
  </code></pre>
  
  <p>Errors with gcc 4.6:</p>
  
  <pre><code>test.cpp: In constructor 'enum_addressable_array&lt;T, size, EnumT&gt;::enum_addressable_array(std::initializer_list&lt;T&gt;) [with T = char, unsigned int size = 3u, EnumT = E]':
  test.cpp:26:55:   instantiated from here
  test.cpp:12:68: error: no matching function for call to 'std::array&lt;char, 3u&gt;::array(&lt;brace-enclosed initializer list&gt;)'
  test.cpp:12:68: note: candidates are:
  include/c++/4.6.1/array:60:12: note: std::array&lt;char, 3u&gt;::array()
  include/c++/4.6.1/array:60:12: note:   candidate expects 0 arguments, 1 provided
  include/c++/4.6.1/array:60:12: note: constexpr std::array&lt;char, 3u&gt;::array(const std::array&lt;char, 3u&gt;&amp;)
  include/c++/4.6.1/array:60:12: note:   no known conversion for argument 1 from 'std::initializer_list&lt;char&gt;' to 'const std::array&lt;char, 3u&gt;&amp;'
  include/c++/4.6.1/array:60:12: note: constexpr std::array&lt;char, 3u&gt;::array(std::array&lt;char, 3u&gt;&amp;&amp;)
  include/c++/4.6.1/array:60:12: note:   no known conversion for argument 1 from 'std::initializer_list&lt;char&gt;' to 'std::array&lt;char, 3u&gt;&amp;&amp;'
  </code></pre>
  
  <p>How can I get it to work so that my wrapper class can be initialized with an initializer-list, as such:</p>
  
  <pre><code>enum_addressable_array&lt;char, 3, E&gt; ea = {'a', 'b', 'c'};
  </code></pre>