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

后端 未结 6 601
刺人心
刺人心 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条回答
  •  旧时难觅i
    2020-12-03 07:16

    std::pair comes with a number of constructors and operators.

    A struct allow named fields (other than first and second) and is ready to be extended at any time.

    Prefer a struct when you can. It may involve some overhead, but is definitely easier for maintenance.

提交回复
热议问题