What is the difference between using a struct with two fields and a pair?

后端 未结 6 602
刺人心
刺人心 2020-12-03 06:42

What is the difference regarding memory allocation and efficiency between using a struct with two fields and a pair?

6条回答
  •  醉话见心
    2020-12-03 07:14

    As this isn't mentioned above, if you want the benefits of your own name, but the advantages of std::pair (or any other objects), you can use "using" ( from c++11 onwards). You can set this in your namespace or class declaration.

    In fact this is how many of my classes now start out...

    using myPair = pair;
    

    cf. C++ reference. for more documentation.

提交回复
热议问题