diff options
author | Paolo Carlini <pcarlini@suse.de> | 2007-11-16 23:41:55 +0000 |
---|---|---|
committer | Paolo Carlini <paolo@gcc.gnu.org> | 2007-11-16 23:41:55 +0000 |
commit | de03de6403a9d483644f3549071bdf3be9a1043b (patch) | |
tree | 64a42b0379ff8b8e9425138a26c12e21fac1c947 /libstdc++-v3 | |
parent | e84296c66c1d63552db6dd6571edd92619a00e53 (diff) | |
download | gcc-de03de6403a9d483644f3549071bdf3be9a1043b.zip gcc-de03de6403a9d483644f3549071bdf3be9a1043b.tar.gz gcc-de03de6403a9d483644f3549071bdf3be9a1043b.tar.bz2 |
stl_algobase.h (struct __lexicographical_compare): Add.
2007-11-16 Paolo Carlini <pcarlini@suse.de>
* include/bits/stl_algobase.h (struct __lexicographical_compare): Add.
(lexicographical_compare<>(_II1, _II1, _II2, _II2)): Use it.
(lexicographical_compare(const unsigned char*, const unsigned char*,
const unsigned char*, const unsigned char*),
lexicographical_compare(const char*, const char*, const char*,
const char*)): Remove.
* include/ext/numeric_traits.h (__numeric_traits_floating<>::
__is_signed): Add.
From-SVN: r130248
Diffstat (limited to 'libstdc++-v3')
-rw-r--r-- | libstdc++-v3/ChangeLog | 11 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/stl_algobase.h | 113 | ||||
-rw-r--r-- | libstdc++-v3/include/ext/numeric_traits.h | 4 |
3 files changed, 68 insertions, 60 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index fd90899..bb88fd1 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,5 +1,16 @@ 2007-11-16 Paolo Carlini <pcarlini@suse.de> + * include/bits/stl_algobase.h (struct __lexicographical_compare): Add. + (lexicographical_compare<>(_II1, _II1, _II2, _II2)): Use it. + (lexicographical_compare(const unsigned char*, const unsigned char*, + const unsigned char*, const unsigned char*), + lexicographical_compare(const char*, const char*, const char*, + const char*)): Remove. + * include/ext/numeric_traits.h (__numeric_traits_floating<>:: + __is_signed): Add. + +2007-11-16 Paolo Carlini <pcarlini@suse.de> + * src/locale_facets.cc: Fix typo in Copyright. 2007-11-16 Paolo Carlini <pcarlini@suse.de> diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h index 0c3f1b2..09d0145 100644 --- a/libstdc++-v3/include/bits/stl_algobase.h +++ b/libstdc++-v3/include/bits/stl_algobase.h @@ -877,6 +877,48 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_P) return true; } + + template<bool _BoolType> + struct __lexicographical_compare + { + template<typename _II1, typename _II2> + static bool + __lc(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2) + { + typedef typename iterator_traits<_II1>::iterator_category _Category1; + typedef typename iterator_traits<_II2>::iterator_category _Category2; + typedef std::__lc_rai<_Category1, _Category2> __rai_type; + + __last1 = __rai_type::__newlast1(__first1, __last1, + __first2, __last2); + for (; __first1 != __last1 && __rai_type::__cnd2(__first2, __last2); + ++__first1, ++__first2) + { + if (*__first1 < *__first2) + return true; + if (*__first2 < *__first1) + return false; + } + return __first1 == __last1 && __first2 != __last2; + } + }; + + template<> + struct __lexicographical_compare<true> + { + template<typename _Tp, typename _Up> + static bool + __lc(const _Tp* __first1, const _Tp* __last1, + const _Up* __first2, const _Up* __last2) + { + const size_t __len1 = __last1 - __first1; + const size_t __len2 = __last2 - __first2; + const int __result = __builtin_memcmp(__first1, __first2, + std::min(__len1, __len2)); + return __result != 0 ? __result < 0 : __len1 < __len2; + } + }; + /** * @brief Performs "dictionary" comparison on ranges. * @param first1 An input iterator. @@ -892,14 +934,10 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_P) * then this is an inline call to @c memcmp. */ template<typename _II1, typename _II2> - bool - lexicographical_compare(_II1 __first1, _II1 __last1, + inline bool + lexicographical_compare(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2) { - typedef typename iterator_traits<_II1>::iterator_category _Category1; - typedef typename iterator_traits<_II2>::iterator_category _Category2; - typedef std::__lc_rai<_Category1, _Category2> __rai_type; - // concept requirements typedef typename iterator_traits<_II1>::value_type _ValueType1; typedef typename iterator_traits<_II2>::value_type _ValueType2; @@ -910,61 +948,16 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_P) __glibcxx_requires_valid_range(__first1, __last1); __glibcxx_requires_valid_range(__first2, __last2); - __last1 = __rai_type::__newlast1(__first1, __last1, __first2, __last2); - for (; __first1 != __last1 && __rai_type::__cnd2(__first2, __last2); - ++__first1, ++__first2) - { - if (*__first1 < *__first2) - return true; - if (*__first2 < *__first1) - return false; - } - return __first1 == __last1 && __first2 != __last2; - } + const bool __simple = + (__is_byte<_ValueType1>::__value && __is_byte<_ValueType2>::__value + && !__gnu_cxx::__numeric_traits<_ValueType1>::__is_signed + && !__gnu_cxx::__numeric_traits<_ValueType2>::__is_signed + && __is_pointer<_II1>::__value + && __is_pointer<_II2>::__value); - // XXX should these be enabled-if'd for signed/unsigned types instead? - inline bool - lexicographical_compare(const unsigned char* __first1, - const unsigned char* __last1, - const unsigned char* __first2, - const unsigned char* __last2) - { - __glibcxx_requires_valid_range(__first1, __last1); - __glibcxx_requires_valid_range(__first2, __last2); - - const size_t __len1 = __last1 - __first1; - const size_t __len2 = __last2 - __first2; - const int __result = __builtin_memcmp(__first1, __first2, - std::min(__len1, __len2)); - return __result != 0 ? __result < 0 : __len1 < __len2; - } - - inline bool - lexicographical_compare(const char* __first1, const char* __last1, - const char* __first2, const char* __last2) - { - __glibcxx_requires_valid_range(__first1, __last1); - __glibcxx_requires_valid_range(__first2, __last2); - - if (__gnu_cxx::__numeric_traits<char>::__is_signed) - { - typedef const signed char* value_type; - value_type __f1 = reinterpret_cast<value_type>(__first1); - value_type __l1 = reinterpret_cast<value_type>(__last1); - value_type __f2 = reinterpret_cast<value_type>(__first2); - value_type __l2 = reinterpret_cast<value_type>(__last2); - return _GLIBCXX_STD_P::lexicographical_compare(__f1, __l1, __f2, __l2); - } - else - { - typedef const unsigned char* value_type; - value_type __f1 = reinterpret_cast<value_type>(__first1); - value_type __l1 = reinterpret_cast<value_type>(__last1); - value_type __f2 = reinterpret_cast<value_type>(__first2); - value_type __l2 = reinterpret_cast<value_type>(__last2); - return _GLIBCXX_STD_P::lexicographical_compare(__f1, __l1, __f2, __l2); - } - } + return _GLIBCXX_STD_P::__lexicographical_compare<__simple>:: + __lc(__first1, __last1, __first2, __last2); + } /** * @brief Performs "dictionary" comparison on ranges. diff --git a/libstdc++-v3/include/ext/numeric_traits.h b/libstdc++-v3/include/ext/numeric_traits.h index 109e37e..29265e7 100644 --- a/libstdc++-v3/include/ext/numeric_traits.h +++ b/libstdc++-v3/include/ext/numeric_traits.h @@ -107,6 +107,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) static const int __max_digits10 = __glibcxx_max_digits10(_Value); // See above comment... + static const bool __is_signed = true; static const int __digits10 = __glibcxx_digits10(_Value); static const int __max_exponent10 = __glibcxx_max_exponent10(_Value); }; @@ -115,6 +116,9 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) const int __numeric_traits_floating<_Value>::__max_digits10; template<typename _Value> + const bool __numeric_traits_floating<_Value>::__is_signed; + + template<typename _Value> const int __numeric_traits_floating<_Value>::__digits10; template<typename _Value> |