r/cpp • u/stanimirov • Jul 04 '18
Be Mindful with Compiler-Generated Move Constructors
https://ibob.github.io/blog/2018/07/03/compiler-generated-move/
89
Upvotes
r/cpp • u/stanimirov • Jul 04 '18
View all comments
11
u/sphere991 Jul 04 '18 edited Jul 04 '18
That's not quite right.
std::functionnever needs to move the underlying type, and wouldn't erase the move constructor anyway - it's unnecessary, it just erases the copy constructor.std::function's move constructor could be made noexcept, and there is a paper that nearly got adopted in Rapperswil that would do just that: P0771. Indeed, on recent versions of libstdc++ and libc++,static_assert(std::is_nothrow_move_constructible_v<std::function<void(int)>>)does not fire.