[cfe-dev] Asymmetric lower_bound

Jakob Stoklund Olesen stoklund at 2pi.dk
Mon Aug 16 14:29:39 PDT 2010


Hi C++ experts,

In X86FloatingPoint.cpp there is a struct TableEntry that can be compared to an unsigned:

    friend bool operator<(const TableEntry &TE, unsigned V) {
      return TE.from < V;
    }

This is used with std::lower_bound():

static int Lookup(const TableEntry *Table, unsigned N, unsigned Opcode) {
  const TableEntry *I = std::lower_bound(Table, Table+N, Opcode);
  ...
}

It looks like the GNU libstdc++ is happy with the asymmetric types in the comparison, but MSVC insists that the transposed operator< also be available:

    friend bool operator<(unsigned V, const TableEntry &TE) {
      return V < TE.from;
    }

It is not really clear from the draft C++0x standard what is required when the comparison function takes asymmetric types.

Is MSVC wrong here, and lower_bound should work with only one asymmetric comparison available?
Is it a bug in the standard that it isn't clearly specified?

/jakob





More information about the cfe-dev mailing list