Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

std::less<void> and pointer types

std::less<T *> is guaranteed to provide total order, regardless of whether both pointers point into the same array.

In the latest draft of the standard, is the same true for the transparent function object std::less<void> (std::less<>) when you call its operator()?

Obviously, the same question applies to std::greater, but I assume they are specified the same.

like image 280
David Stone Avatar asked Jan 12 '14 20:01

David Stone


1 Answers

The current draft from github does not contain any language to that effect; in fact, its definition of less<> says explicitly "returns std::forward<T>(t) < std::forward<U>(u)", which would be undefined behaviour for incomparable pointers. So... don't do it, I suppose.

If you need a heterogeneous pointer comparator, it's probably best to write your own template predicate which uses std::less<T*>() at the appropriate moment.

like image 193
Kerrek SB Avatar answered Oct 22 '22 11:10

Kerrek SB