Namespaces
Variants
Views
Actions

Talk:cpp/container/vector/operator=

From cppreference.com
< Talk:cpp‎ | container‎ | vector
Revision as of 14:51, 7 September 2016 by 90.194.176.82 (Talk)

The following is missing: vector& operator=(initializer_list<T>);

Thanks for noticing that. I believe I've fixed the omission. P12 05:03, 6 July 2013 (PDT)


Self-Assignment

Presumably (1) no-ops with self assignment. I've spent a few hours on Google and I can't seem to find anything that explicitly says this is a requirement. If you know which part of the standard say it must that would be nice to refer to. (The code for the gcc implementation on github does: https://github.com/gcc-mirror/gcc/blob/master/libstdc%2B%2B-v3/include/bits/stl_bvector.h but I'd be looking for a reference to the standard really).

The contrast with (2) would be... instructive. It appears that for the move assignment the standard does NOT require STL containers to no-op with self-assignment. I can refer you to this StackOverflow post stackoverflow.com/questions/13127455/ which quotes 17.6.4.9 of the Standard, "If a [STL] function argument binds to an rvalue reference parameter, the implementation may assume that this parameter is a unique reference to this argument."

90.194.176.82 15:51, 7 September 2016 (PDT)