[cfe-dev] vector insert in libc++ release_34

Howard Hinnant howard.hinnant at gmail.com
Wed Jan 22 08:47:15 PST 2014


On Jan 22, 2014, at 2:20 AM, Dan Dylan <dany.dylan at gmail.com> wrote:

> The code for vector insert method
> 
> template <class _Tp, class _Allocator>
> template <class _ForwardIterator>
> typename enable_if
> <
>     __is_forward_iterator<_ForwardIterator>::value &&
>     is_constructible<
>        _Tp,
>        typename iterator_traits<_ForwardIterator>::reference>::value,
>     typename vector<_Tp, _Allocator>::iterator
> >::type
> vector<_Tp, _Allocator>::insert(const_iterator __position, _ForwardIterator __first, _ForwardIterator __last)
> 
> (starting at line 1870 in file include/vector) requires that _ForwardIterator be copy assignable at line 1900.
> 
> Normally forward iterators will be copy assignable, but there are cases when the iterator is not.  One such case is when using boost::filter_iterator with a Predicate type that is not copy assignable.
> 
> Does _ForwardIterator have to be copy assignable? or
> Is the use of the enable_if template incomplete for this case? or
> Is this a fault in boost::filter_iterator with its traits specification?
> Or is the code wrong?  (there's a simple fix to it, but it may be too simple!) or
> Something else?
> 
> Attached is a short program that exhibits the problem.  It compiles and runs with gcc 4.8.1 and clang 3.4 when using gcc's includes.  It fails to compile when using libc++ includes.

24.2.2 [iterator.iterators]/p2 describes some blanket requirements for all iterators.  It includes:

• A type X satisfies the Iterator requirements if:
  — X satisfies the CopyConstructible, CopyAssignable, and ...
                                       ^^^^^^^^^^^^^^

Yes, forward iterators (and unfortunately even input iterators) have to be copy assignable.

Howard





More information about the cfe-dev mailing list