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

### 1029. Specialized algorithms for memory management need to be concept-constrained templates

Section: 25.11 [specialized.algorithms] Status: NAD Concepts Submitter: Alisdair Meredith Opened: 2009-03-11 Last modified: 2016-01-28

Priority: Not Prioritized

View other active issues in [specialized.algorithms].

View all other issues in [specialized.algorithms].

View all issues with NAD Concepts status.

Discussion:

Addresses UK 210 [CD1]

Related to 582

Specialized algorithms for memory management need requirements to be easily usable in constrained templates.

[ Summit: ]

> We look forward to a paper on this topic. We recommend no action until a paper is available.

[ Post Summit Alisdair provided wording. ]

[ Post Summit: ]

> Daniel adds:

> > 1. I suggest `Size` should require `IntegralLike` and not `UnsignedIntegralLike`, because otherwise simple int-literals could not be provided as arguments and it would conflict with other algorithms that only require `IntegralLike`.

> > 2. The current for-loop-test relies on evaluation in boolean context which is not provided by `ArithmeticLike` and it's refinements. I propose to change the corresponding for-loop-headers to:

> >    1. for `uninitialized_copy_n`: `for ( ; n > Size(0); ++result, ++first, --n) {`
> >    2. for `uninitialized_fill_n`: `for (; n > Size(0); ++first, --n) {`

> Alisdair adds:

> > For the record I agree with Daniel's suggestion.

Proposed resolution:

20.10 [memory] p2

Update the synopsis for `<memory>`

>     template <class InputIterator InIter,
>              class ForwardIterator OutputIterator<auto, InIter::reference> OutIter>
>        requires ForwardIterator<OutIter>
>        ForwardIterator OutIter
>        uninitialized_copy(InputIterator InIter first, InputIterator InIter last,
>                           ForwardIterator OutIter result);

>     template <class InputIterator InIter,
>               class IntegralLike Size,
>               class ForwardIterator OutputIterator<auto, InIter::reference> OutIter>
>       requires ForwardIterator<OutIter>
>       ForwardIterator OutIter
>       uninitialized_copy_n(InputIterator InIter first, Size n,
>                            ForwardIterator OutIter result);

>     template <class ForwardIterator Iter, class ObjectType T>
>       requires Constructible< Iter::value_type, const T& >
>       void uninitialized_fill(ForwardIterator Iter first, ForwardIterator Iter last,
>                               const T& x);

>     template <class ForwardIterator Iter, class IntegralLike Size, class ObjectType T>
>       requires Constructible< Iter::value_type, const T& >
>       void
>       uninitialized_fill_n(ForwardIterator Iter first, Size n, const T& x);

Update as follows:

uninitialized_copy 25.11.5 [uninitialized.copy]

>     template <class InputIterator InIter,
>              class ForwardIterator OutputIterator<auto, InIter::reference> OutIter>
>        requires ForwardIterator<OutIter>
>        ForwardIterator OutIter
>        uninitialized_copy(InputIterator InIter first, InputIterator InIter last,
>                           ForwardIterator OutIter result);

> > -1- Effects:

> > >     for (; first != last; ++result, ++first)  {
> > >        new (static_cast<void*>(&*result))
> > >            typename iterator_traits<ForwardIterator> OutIter::value_type(*first);
> > >     }

> > -2- Returns: `result`

>     template <class InputIterator InIter,
>               class IntegralLike Size,
>               class ForwardIterator OutputIterator<auto, InIter::reference> OutIter>
>       requires ForwardIterator<OutIter>
>       ForwardIterator OutIter
>       uninitialized_copy_n(InputIterator InIter first, Size n,
>                            ForwardIterator OutIter result);

> > -3- Effects:

> > >     for ( ; n > Size(0); ++result, ++first, --n) {
> > >        new (static_cast<void*>(&*result))
> > >            typename iterator_traits<ForwardIterator> OutIter::value_type(*first);
> > >     }

> > -4- Returns: result

uninitialized_fill 25.11.7 [uninitialized.fill]

>     template <class ForwardIterator Iter, class ObjectType T>
>       requires Constructible< Iter::value_type, const T& >
>       void uninitialized_fill(ForwardIterator Iter first, ForwardIterator Iter last,
>                               const T& x);

> > -1- Effects:

> > >     for (; first != last; ++first) {
> > >        new ( static_cast<void*>( &*first) )
> > >            typename iterator_traits<ForwardIterator> Iter::value_type(x);
> > >     }

uninitialized_fill_n [uninitialized.fill.n]

>     template <class ForwardIterator Iter, class IntegralLike Size, class ObjectType T>
>       requires Constructible< Iter::value_type, const T& >
>       void
>       uninitialized_fill_n(ForwardIterator Iter first, Size n, const T& x);

> > -1- Effects:

> > >     for (; n-- > Size(0); ++first, --n) {
> > >        new ( static_cast<void*>( &*first) )
> > >            typename iterator_traits<ForwardIterator> Iter::value_type(x);
> > >     }