Commit de03de64 by Paolo Carlini Committed by Paolo Carlini

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
parent e84296c6
2007-11-16 Paolo Carlini <pcarlini@suse.de> 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. * src/locale_facets.cc: Fix typo in Copyright.
2007-11-16 Paolo Carlini <pcarlini@suse.de> 2007-11-16 Paolo Carlini <pcarlini@suse.de>
......
...@@ -877,40 +877,20 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_P) ...@@ -877,40 +877,20 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_P)
return true; return true;
} }
/**
* @brief Performs "dictionary" comparison on ranges. template<bool _BoolType>
* @param first1 An input iterator. struct __lexicographical_compare
* @param last1 An input iterator. {
* @param first2 An input iterator.
* @param last2 An input iterator.
* @return A boolean true or false.
*
* "Returns true if the sequence of elements defined by the range
* [first1,last1) is lexicographically less than the sequence of elements
* defined by the range [first2,last2). Returns false otherwise."
* (Quoted from [25.3.8]/1.) If the iterators are all character pointers,
* then this is an inline call to @c memcmp.
*/
template<typename _II1, typename _II2> template<typename _II1, typename _II2>
bool static bool
lexicographical_compare(_II1 __first1, _II1 __last1, __lc(_II1 __first1, _II1 __last1, _II2 __first2, _II2 __last2)
_II2 __first2, _II2 __last2)
{ {
typedef typename iterator_traits<_II1>::iterator_category _Category1; typedef typename iterator_traits<_II1>::iterator_category _Category1;
typedef typename iterator_traits<_II2>::iterator_category _Category2; typedef typename iterator_traits<_II2>::iterator_category _Category2;
typedef std::__lc_rai<_Category1, _Category2> __rai_type; typedef std::__lc_rai<_Category1, _Category2> __rai_type;
// concept requirements __last1 = __rai_type::__newlast1(__first1, __last1,
typedef typename iterator_traits<_II1>::value_type _ValueType1; __first2, __last2);
typedef typename iterator_traits<_II2>::value_type _ValueType2;
__glibcxx_function_requires(_InputIteratorConcept<_II1>)
__glibcxx_function_requires(_InputIteratorConcept<_II2>)
__glibcxx_function_requires(_LessThanOpConcept<_ValueType1, _ValueType2>)
__glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>)
__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); for (; __first1 != __last1 && __rai_type::__cnd2(__first2, __last2);
++__first1, ++__first2) ++__first1, ++__first2)
{ {
...@@ -921,49 +901,62 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_P) ...@@ -921,49 +901,62 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_P)
} }
return __first1 == __last1 && __first2 != __last2; return __first1 == __last1 && __first2 != __last2;
} }
};
// XXX should these be enabled-if'd for signed/unsigned types instead? template<>
inline bool struct __lexicographical_compare<true>
lexicographical_compare(const unsigned char* __first1, {
const unsigned char* __last1, template<typename _Tp, typename _Up>
const unsigned char* __first2, static bool
const unsigned char* __last2) __lc(const _Tp* __first1, const _Tp* __last1,
const _Up* __first2, const _Up* __last2)
{ {
__glibcxx_requires_valid_range(__first1, __last1);
__glibcxx_requires_valid_range(__first2, __last2);
const size_t __len1 = __last1 - __first1; const size_t __len1 = __last1 - __first1;
const size_t __len2 = __last2 - __first2; const size_t __len2 = __last2 - __first2;
const int __result = __builtin_memcmp(__first1, __first2, const int __result = __builtin_memcmp(__first1, __first2,
std::min(__len1, __len2)); std::min(__len1, __len2));
return __result != 0 ? __result < 0 : __len1 < __len2; return __result != 0 ? __result < 0 : __len1 < __len2;
} }
};
/**
* @brief Performs "dictionary" comparison on ranges.
* @param first1 An input iterator.
* @param last1 An input iterator.
* @param first2 An input iterator.
* @param last2 An input iterator.
* @return A boolean true or false.
*
* "Returns true if the sequence of elements defined by the range
* [first1,last1) is lexicographically less than the sequence of elements
* defined by the range [first2,last2). Returns false otherwise."
* (Quoted from [25.3.8]/1.) If the iterators are all character pointers,
* then this is an inline call to @c memcmp.
*/
template<typename _II1, typename _II2>
inline bool inline bool
lexicographical_compare(const char* __first1, const char* __last1, lexicographical_compare(_II1 __first1, _II1 __last1,
const char* __first2, const char* __last2) _II2 __first2, _II2 __last2)
{ {
// concept requirements
typedef typename iterator_traits<_II1>::value_type _ValueType1;
typedef typename iterator_traits<_II2>::value_type _ValueType2;
__glibcxx_function_requires(_InputIteratorConcept<_II1>)
__glibcxx_function_requires(_InputIteratorConcept<_II2>)
__glibcxx_function_requires(_LessThanOpConcept<_ValueType1, _ValueType2>)
__glibcxx_function_requires(_LessThanOpConcept<_ValueType2, _ValueType1>)
__glibcxx_requires_valid_range(__first1, __last1); __glibcxx_requires_valid_range(__first1, __last1);
__glibcxx_requires_valid_range(__first2, __last2); __glibcxx_requires_valid_range(__first2, __last2);
if (__gnu_cxx::__numeric_traits<char>::__is_signed) const bool __simple =
{ (__is_byte<_ValueType1>::__value && __is_byte<_ValueType2>::__value
typedef const signed char* value_type; && !__gnu_cxx::__numeric_traits<_ValueType1>::__is_signed
value_type __f1 = reinterpret_cast<value_type>(__first1); && !__gnu_cxx::__numeric_traits<_ValueType2>::__is_signed
value_type __l1 = reinterpret_cast<value_type>(__last1); && __is_pointer<_II1>::__value
value_type __f2 = reinterpret_cast<value_type>(__first2); && __is_pointer<_II2>::__value);
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);
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);
}
} }
/** /**
......
...@@ -107,6 +107,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) ...@@ -107,6 +107,7 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
static const int __max_digits10 = __glibcxx_max_digits10(_Value); static const int __max_digits10 = __glibcxx_max_digits10(_Value);
// See above comment... // See above comment...
static const bool __is_signed = true;
static const int __digits10 = __glibcxx_digits10(_Value); static const int __digits10 = __glibcxx_digits10(_Value);
static const int __max_exponent10 = __glibcxx_max_exponent10(_Value); static const int __max_exponent10 = __glibcxx_max_exponent10(_Value);
}; };
...@@ -115,6 +116,9 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx) ...@@ -115,6 +116,9 @@ _GLIBCXX_BEGIN_NAMESPACE(__gnu_cxx)
const int __numeric_traits_floating<_Value>::__max_digits10; const int __numeric_traits_floating<_Value>::__max_digits10;
template<typename _Value> template<typename _Value>
const bool __numeric_traits_floating<_Value>::__is_signed;
template<typename _Value>
const int __numeric_traits_floating<_Value>::__digits10; const int __numeric_traits_floating<_Value>::__digits10;
template<typename _Value> template<typename _Value>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment