This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of NAD Arrays status.

### 2264. [arrays.ts] `std::dynarray` defines its initializer-list constructor in terms of a non-existent constructor

Section: 99 [arrays.ts::dynarray], 99 [arrays.ts::container.requirements] Status: NAD Arrays Submitter: Povilas Kanapickas Opened: 2013-05-22 Last modified: 2016-03-08

Priority: 1

View all issues with NAD Arrays status.

Discussion:

Addresses: arrays.ts

`std::dynarray` member listing at 99 [arrays.ts::dynarray.overview] includes this constructor:

>     dynarray(initializer_list<T>);

Also, 99 [arrays.ts::dynarray.overview] p. 2 says:

> Unless otherwise specified, all `dynarray` operations have the same requirements and semantics as specified in 23.2.

The constructor in question isn't mentioned in 99 [arrays.ts::dynarray.cons] or anywhere else. This means requirements from 99 [arrays.ts::container.requirements] apply. However, Table 100 in 24.2.4 [sequence.reqmts] says:

> `X(il)` Equivalent to `X(il.begin(), il.end())`

`std::dynarray` does not provide this constructor.

The proposed resolution below adds the missing constructor and a complementary constructor with an allocator parameter. The new constructors, differently from the rest of containers, accept iterators that have forward iterator category. This is needed because the size requirements must be known in order to allocate appropriately-sized storage.

An alternative resolution could be to properly specify the initializer-list constructor.

[2013-09 Chicago:]

Move to Deferred. This feature will ship after C++14 and should be revisited then.

[2014-06-06 pre-Rapperswill]

This issue has been reopened as arrays-ts.

Proposed resolution:

1. Add the following to the `std::dynarray` synopsis at 99 [arrays.ts::dynarray.overview]:

   >     namespace std {
   >       template <class T>
   >       class dynarray {
   >         […]
   >         // 23.3.4.2 construct/copy/destroy:
   >         […]
   >         template <class ForwardIterator>
   >         dynarray(ForwardIterator first, ForwardIterator last);
   >         template <class ForwardIterator, class Alloc>
   >         dynarray(ForwardIterator first, ForwardIterator last, const Alloc& alloc);
   >         […]
   >       };
   >     }

2. Add the following to 99 [arrays.ts::dynarray.cons] after p. 8:

   >     template <class ForwardIterator>
   >     dynarray(ForwardIterator first, ForwardIterator last);

   > > -?- Requires: `T` shall meet the `CopyConstructible` requirements.

   > > -?- Effects: Allocates storage for `distance(first, last)` elements. The `distance(first, last)` elements of the dynarray are direct-initialized (9.4 [dcl.init]) with the corresponding elements from the range `[first,last)`. May or may not invoke the global `operator new`.

   > > -?- Complexity: `distance(first, last)`.

   > > -?- Throws: `std::bad_array_length` when the size requested is larger than implementable, `std::bad_alloc` when there is insufficient memory.

3. Add the following to the list of constructors at 99 [arrays.ts::dynarray.cons] before p. 9:

   >     template <class Alloc>
   >     dynarray(size_type c, const Alloc& alloc);
   >     template <class Alloc>
   >     dynarray(size_type c, const T& v, const Alloc& alloc);
   >     template <class Alloc>
   >     dynarray(const dynarray& d, const Alloc& alloc);
   >     template <class Alloc>
   >     dynarray(initializer_list<T>, const Alloc& alloc);
   >     template <class ForwardIterator, class Alloc>
   >     dynarray(ForwardIterator first, ForwardIterator last, const Alloc& alloc);