Get the App
SLTechnology News&Howtos  ›  Development  › 

What about Expression:invalid comarator?

Shulou Source: shulou.com Published: 2022-06-02 12:15:39 11月21日 Update

This article is to share with you what to do with Expression:invalid comarator. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Scene

The functions are defined as follows:

Template struct greaterkey {/ / is used to specify sorting and decreasing in map, and increment by default in map

Bool operator () (const T & x, const T & y) const

{

Return x > y

}

}

Template struct lesskey {

Bool operator () (const T & x, const T & y) const

{

Return x < y

}

}

Solve

After vs2010, there is a strict comparison. If the two elements are equal, be sure to return false. You can see the source code of STL:

[cpp]

Template inline

Bool _ Debug_lt_pred (_ Pr _ Pred

_ Ty1& _ Left, _ Ty2& _ Right

_ Dbfile_t _ File, _ Dbline_t _ Line)

{/ / test if _ Pred (_ Left, _ Right) and _ Pred is strict weak ordering

If (! _ Pred (_ Left, _ Right))

Return (false)

Else if (_ Pred (_ Right, _ Left))

_ DEBUG_ERROR2 ("invalid operator

Tags: What to do content more articles sort good practical two code elements functions scenarios articles time source code see knowledge will report reference help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Microsoft MariaDB NVidia Apple