std::sort does not always call std::swap

后端 未结 3 1310
独厮守ぢ
独厮守ぢ 2020-11-27 21:51

Consider the following code:

#include 
#include 
#include 

namespace my_space
{

struct A
{
    double  a;
           


        
3条回答
  •  暖寄归人
    2020-11-27 21:52

    Depending on the type, swapping can be more expensive than a move-assignment (in C++98 a simple assignment). The standard library doesn't have any way to detect these cases. At least in C++11 the solution is clear: implement a move-assignment operator for all classes where you implement swap.

提交回复
热议问题