Operator< and strict weak ordering

前端 未结 6 1912
醉酒成梦
醉酒成梦 2020-11-22 03:51

How to define operator< on n-tuple (for example on 3-tuple) so that it satisfy strict weak ordering concept ? I know that boost library has

6条回答
  •  醉话见心
    2020-11-22 04:25

    Even if you can't use the boost version, you should be able to nick the code. I nicked this from std::pair - a 3 tuple will be similar I guess.

    return (_Left.first < _Right.first ||
            !(_Right.first < _Left.first) && _Left.second < _Right.second);
    

    Edit: As a couple of people have pointed out, if you steal code from the standard library to use in your code, you should rename things that have underscores on the front as these names are reserved.

提交回复
热议问题