C++/CX:STL comparison operator (<) overloading

小于操作符重载

The less-than comparison operator (operator<) is important to Standard Template Library operations such as sorting. We recommend that you implement operator< if you develop a Windows Runtime component that you intend to be used in a Standard Template Library comparison operation.

小于比较操作符对于标准库来说是比较重要的,如排序。如果你开发一个windows Runtime component,并且你准备使用标准库中的小于比较操作,建议你重载小于操作符。

The details about how to implement the less-than operator depend on your Windows Runtime component. However, here are two guidelines to consider:

关于如何实现小于比较操作符的细节,依赖于你的windows runtime component。然后下面两条建议必须考虑:

1.If you compare two reference class objects, first test whether one or both comparands is equal to nullptr; that is, test whether the comparands are valid references. If one or both comparands are invalid, return an appropriate value.

如果你比较两个引用类的对象,首先需要检查一个或者两个比较对象是否为nullPtr,即比较对象合法性判断。如果一个或者两个为非法的,返回一个合适的值。

2.If both comparands are valid, return the results of a comparison that is a strict weak ordering of the types of your comparands. For more information about strict weak ordering, see Algorithms.

如果两个比较对象都是合法的,则返回一个比较严格的弱序比较对象。具体关于严格弱序,请查看算法。

posted @ 2012-06-17 15:22  狼哥2  阅读(325)  评论(0编辑  收藏  举报