Move Semantics for POD-ish types

前端 未结 3 1612
隐瞒了意图╮
隐瞒了意图╮ 2021-02-20 04:31

Is there any point implementing a move constructor and move assignment operator for a struct or class that contains only primitive types? For instance,

struct Fo         


        
3条回答
  •  礼貌的吻别
    2021-02-20 05:05

    Note that a fully conforming C++11/14 compiler (not current version of VS2013) should automatically generate move operations for your Bar struct:

    struct Bar
    {
        float x,y,z;
        std::string Name;
    };
    

    In general, you should write move operations explicitly only for direct resource managers, that act like "building blocks". When you assemble together building blocks in more complex classes, the compiler should automatically generate move operations (using member-wise moves).

提交回复
热议问题