[cfe-dev] std::vector insert type requirements

Balázs Kéri via cfe-dev cfe-dev at lists.llvm.org
Tue Jul 3 06:14:00 PDT 2018


Hi,
If you construct with copy, the copy constructor is used.
The insert operation works (I think) by copying new items over the old
items, not by constructing new items, so the copy assignment is needed (if
not the move iterator is used).

Nikita Alekseev via cfe-dev <cfe-dev at lists.llvm.org> ezt írta (időpont:
2018. júl. 3., K, 14:05):

> Hello everyone, I hope this mailing list is the right place to ask about
> this. When I try to compile this particular code
> sample https://godbolt.org/g/J7cgbV I get an error, that A must have a
> copy assignment operator. However when reading the documentation
> at https://en.cppreference.com/w/cpp/container/vector/insert I do not
> see any such requirements for this particular overload of insert. It
> does mention that T must be moveAssignable and MoveInsertable if
> Iterator is not ForwardIterator. Even if I define move assignment
> operator it still requires copy assignment.
>
> I have tested it on Clang 4, Clang 6, GCC 8.1 and get the same error.
> MSVC 2017 compiles when move assignment is present. It would be great if
> someone could explain this behavior.
>
>
> hi,
> please look at:
> https://en.cppreference.com/w/cpp/iterator/make_move_iterator
>
>
> I am afraid this is not what I am trying to achieve. I want to copy vector
> contents via insert, but why it  requires copy assignment to be defined in
> order to compile? Simple construction from the pair of iterators works
> without it.
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20180703/69aeb485/attachment.html>


More information about the cfe-dev mailing list