c++ - Is sort() automatically using move semantics? -
isocpp.org states that:
move-based std::sort() , std::set::insert() have been measured 15 times faster copy based versions[...] if type has move operation, gain performance benefits automatically standard algorithms.
does mean if call sort()
on user-defined type has no move constructor or move assignment operator, there no move semantics used? in other words, many benefits of c++11 performance improvements, should edit existing code add move operations explicitly?
further, if sorting, container or type inside container, or both, must have move operations defined?
does mean if call
sort()
on user-defined type has no move constructor or move assignment operator, there no move semantics used?
correct. if class not moveable fall copying
in other words, many benefits of c++11 performance improvements, should edit existing code add move operations explicitly?
if can sure, doesn't more performance. note depending on class may automatically generated move operations.
further, if sorting, container or type inside container, or both, must have move operations defined?
the container not required moveable. std::sort
requires iterator passed shall satisfy requirements of valueswappable (17.6.3.2). , type returned dereferencing iterator shall satisfy requirements of moveconstructible (table 20) , of moveassignable (table 22).
Comments
Post a Comment