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

Marshall Clow mclow.lists at gmail.com
Wed Jan 22 09:01:53 PST 2014


On Jan 21, 2014, at 11:20 PM, 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?

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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140122/4cea8498/attachment.html>


More information about the cfe-dev mailing list