STL-pair-like triplet class - do I roll my own?

前端 未结 5 619
感动是毒
感动是毒 2021-01-03 18:52

I want to use a triplet class, as similar as possible to std::pair. STL doesn\'t seem to have one. I don\'t want to use something too heavy, like Boost. Is there some useful

5条回答
  •  悲&欢浪女
    2021-01-03 19:11

    To add the aspect of similarity to std::pair, you could define a class that has first, second and third. My guess is that in In that case you cannot avoid making a subclass of std::pair and add a 'third' member. It's a few lines of code.

    Furthermore, if you often use these things with the same type, you could make twins and triplet classes as well. Easily made with C++-11's 'using', like:

    template  using twins = std::pair;
    

提交回复
热议问题