diff options
Diffstat (limited to 'gcc-4.4.3/libstdc++-v3/include/bits')
-rw-r--r-- | gcc-4.4.3/libstdc++-v3/include/bits/stl_algo.h | 7 | ||||
-rw-r--r-- | gcc-4.4.3/libstdc++-v3/include/bits/stl_tree.h | 26 |
2 files changed, 22 insertions, 11 deletions
diff --git a/gcc-4.4.3/libstdc++-v3/include/bits/stl_algo.h b/gcc-4.4.3/libstdc++-v3/include/bits/stl_algo.h index f54b1cd77..d4b04d1da 100644 --- a/gcc-4.4.3/libstdc++-v3/include/bits/stl_algo.h +++ b/gcc-4.4.3/libstdc++-v3/include/bits/stl_algo.h @@ -74,13 +74,12 @@ _GLIBCXX_BEGIN_NAMESPACE(std) #if __google_stl_debug_compare template<typename _Compare> struct _CheckedCompare { - // Mutable because some clients use non-const operator(). - mutable _Compare _M_compare; + _Compare _M_compare; _CheckedCompare(const _Compare & __comp): _M_compare(__comp) { } template <typename _Tp> - bool operator()(const _Tp& __x, const _Tp& __y) const { + bool operator()(const _Tp& __x, const _Tp& __y) { if (_M_compare(__x, __x)) __throw_runtime_error("strict weak ordering: (__x LT __x) != false"); if (_M_compare(__y, __y)) @@ -96,7 +95,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) // indexterm/internal/numericterms.cc // fails without this. template <typename _Tp1, typename _Tp2> - bool operator()(const _Tp1& __x, const _Tp2& __y) const { + bool operator()(const _Tp1& __x, const _Tp2& __y) { return _M_compare(__x, __y); } }; diff --git a/gcc-4.4.3/libstdc++-v3/include/bits/stl_tree.h b/gcc-4.4.3/libstdc++-v3/include/bits/stl_tree.h index 4f0ad2d8d..e2cc1518d 100644 --- a/gcc-4.4.3/libstdc++-v3/include/bits/stl_tree.h +++ b/gcc-4.4.3/libstdc++-v3/include/bits/stl_tree.h @@ -456,22 +456,34 @@ _GLIBCXX_BEGIN_NAMESPACE(std) #if __google_stl_debug_rbtree template<typename _KeyCompare> struct _CheckedCompare { - // Mutable because some clients use non-const operator(). - mutable _KeyCompare _M_key_compare; + _KeyCompare _M_key_compare; _CheckedCompare(): _M_key_compare() { } _CheckedCompare(const _KeyCompare & __comp): _M_key_compare(__comp) { } - bool operator()(const _Key& __x, const _Key& __y) const { - if (_M_key_compare(__x, __x)) + // Template arg required to avoid duplicating code in the two op() + // operators below. User-provided _M_key_compare may not be const, + // but needs to be callable from our const op(). + // See http://b/1731200 for details. + template <typename _KeyCompareT> + static bool _M_compare_with(_KeyCompareT& __comp, const _Key& __x, const _Key& __y) { + if (__comp(__x, __x)) __throw_runtime_error("strict weak ordering: (__x LT __x) != false"); - if (_M_key_compare(__y, __y)) + if (__comp(__y, __y)) __throw_runtime_error("strict weak ordering: (__y LT __y) != false"); - bool lt = _M_key_compare(__x, __y); - if (lt && _M_key_compare(__y, __x)) + bool lt = __comp(__x, __y); + if (lt && __comp(__y, __x)) __throw_runtime_error("strict weak ordering: ((__x LT __y) && (__y LT __x)) != false"); return lt; } + bool operator()(const _Key& __x, const _Key& __y) const { + return _M_compare_with(_M_key_compare, __x, __y); + } + + bool operator()(const _Key& __x, const _Key& __y) { + return _M_compare_with(_M_key_compare, __x, __y); + } + operator _KeyCompare() const { return _M_key_compare; } }; |