vector insert in libc++ release_34

The code for vector insert method

template <class _Tp, class _Allocator>
template
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.

Cheers
Dan

vector.cpp (1.25 KB)

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

I believe so.

24.2.2/2 (Iterator) says:

• A type X satisfies the Iterator requirements if:
— X satisfies the CopyConstructible, CopyAssignable, and Destructible requirements (17.6.3.1) and lvalues of type X are swappable (17.6.3.2), and
— the expressions in Table 106 are valid and have the indicated semantics.
… and so on.

    • and - -
      24.2.3/1 (Input Iterator) says:

• A class or pointer type X satisfies the requirements of an input iterator for the value type T if X satisfies the Iterator (24.2.2) and EqualityComparable (Table 17) requirements and the expressions in Table 107 are valid and have the indicated semantics.

… and so on.

    • and (finally!) - -

24.2.5/1 (Forward Iterator) says:

• A class or pointer type X satisfies the requirements of a forward iterator if
• — X satisfies the requirements of an input iterator (24.2.3),

• — X satisfies the DefaultConstructible requirements (17.6.3.1),

… and so on.

So, to be a forward iterator is to be an input iterator is to be an iterator … which means it has to be CopyConstructible and CopyAssignable.

— Marshall