summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorJordan Rose <jordan_rose@apple.com>2014-04-23 22:44:11 +0000
committerJordan Rose <jordan_rose@apple.com>2014-04-23 22:44:11 +0000
commite45bc94232040786131bf0aee9eaed0cc44bb534 (patch)
tree4cc7b012c2eac864f2d6fe9a49980dfbe1083a3c /include
parent88508669ffb56dff508d26a38a472c392e8cb6bc (diff)
downloadllvm-e45bc94232040786131bf0aee9eaed0cc44bb534.tar.gz
llvm-e45bc94232040786131bf0aee9eaed0cc44bb534.tar.bz2
llvm-e45bc94232040786131bf0aee9eaed0cc44bb534.tar.xz
Use std::less instead of < in array_pod_sort's default comparator.
This makes array_pod_sort portably safe to use with pointers. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@207043 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/llvm/ADT/STLExtras.h11
1 files changed, 6 insertions, 5 deletions
diff --git a/include/llvm/ADT/STLExtras.h b/include/llvm/ADT/STLExtras.h
index fc45a6645e..7c2a147bc8 100644
--- a/include/llvm/ADT/STLExtras.h
+++ b/include/llvm/ADT/STLExtras.h
@@ -171,13 +171,14 @@ LLVM_CONSTEXPR inline size_t array_lengthof(T (&)[N]) {
return N;
}
-/// array_pod_sort_comparator - This is helper function for array_pod_sort,
-/// which just uses operator< on T.
+/// Adapt std::less<T> for array_pod_sort.
template<typename T>
inline int array_pod_sort_comparator(const void *P1, const void *P2) {
- if (*reinterpret_cast<const T*>(P1) < *reinterpret_cast<const T*>(P2))
+ if (std::less<T>()(*reinterpret_cast<const T*>(P1),
+ *reinterpret_cast<const T*>(P2)))
return -1;
- if (*reinterpret_cast<const T*>(P2) < *reinterpret_cast<const T*>(P1))
+ if (std::less<T>()(*reinterpret_cast<const T*>(P2),
+ *reinterpret_cast<const T*>(P1)))
return 1;
return 0;
}
@@ -200,7 +201,7 @@ inline int (*get_array_pod_sort_comparator(const T &))
/// possible.
///
/// This function assumes that you have simple POD-like types that can be
-/// compared with operator< and can be moved with memcpy. If this isn't true,
+/// compared with std::less and can be moved with memcpy. If this isn't true,
/// you should use std::sort.
///
/// NOTE: If qsort_r were portable, we could allow a custom comparator and