C++ Tuple vs Struct

后端 未结 12 1825
耶瑟儿~
耶瑟儿~ 2020-12-07 10:51

Is there is any difference between using a std::tuple and a data-only struct?

typedef std::tuple foo_t;

s         


        
12条回答
  •  醉酒成梦
    2020-12-07 11:46

    Don't worry about speed or layout, that's nano-optimisation, and depends on the compiler, and there's never enough difference to influence your decision.

    You use a struct for things that meaningfully belong together to form a whole.

    You use a tuple for things that are together coincidentally. You can use a tuple spontaneously in your code.

提交回复
热议问题