桜、抹茶、白、日記

名古屋市在住のC++使いのcoderの日記だったもの。

Assertion Failure When Sorting STL Vector using Custom Predicate

VC++2010で寝ぼけた小なり演算子(operator <)の実装を書いていたら、デバッグ版実行時にassertが出た。

Assertion Failure When Sorting STL Vector using Custom Predicate
http://support.microsoft.com/kb/949171

VC++2005以降だとおかしな実装の場合にassertされるのか。

The STL algorithms for stable_sort() and sort() require the binary predicate to be strict weak ordering.
For example:

    • Strict: pred(X, X) is always false.
    • Weak: If !pred(X, Y) && !pred(Y, X), X==Y.
    • Ordering: If pred(X, Y) && pred(Y, Z), then pred(X, Z).

STLのリファレンスというかC++の規格書あたりにも書いてあるのだろうか。