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
This commit is contained in:
parent
e84296c66c
commit
de03de6403
@ -1,3 +1,14 @@
|
||||
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.
|
||||
|
@ -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,62 +948,17 @@ _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);
|
||||
|
||||
return _GLIBCXX_STD_P::__lexicographical_compare<__simple>::
|
||||
__lc(__first1, __last1, __first2, __last2);
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Performs "dictionary" comparison on ranges.
|
||||
* @param first1 An input iterator.
|
||||
|
@ -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);
|
||||
};
|
||||
@ -114,6 +115,9 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
|
||||
template<typename _Value>
|
||||
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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user