Commit 394033f8 by Paolo Carlini Committed by Paolo Carlini

cpp_type_traits.h (__is_byte): Add.

2007-10-17  Paolo Carlini  <pcarlini@suse.de>

	* include/bits/cpp_type_traits.h (__is_byte): Add.
	* include/bits/stl_algobase.h (struct __fill, struct __fill_n,
	__fill_aux, __fill_n_aux): Remove.
	(__fill_a, __fill_n_a): Add.
	(fill, fill_n): Adjust.

From-SVN: r129421
parent f8da8190
2007-10-17 Paolo Carlini <pcarlini@suse.de> 2007-10-17 Paolo Carlini <pcarlini@suse.de>
* include/bits/cpp_type_traits.h (__is_byte): Add.
* include/bits/stl_algobase.h (struct __fill, struct __fill_n,
__fill_aux, __fill_n_aux): Remove.
(__fill_a, __fill_n_a): Add.
(fill, fill_n): Adjust.
2007-10-17 Paolo Carlini <pcarlini@suse.de>
* include/bits/stl_iterator.h (back_insert_iterator<>::operator= * include/bits/stl_iterator.h (back_insert_iterator<>::operator=
(typename _Container::value_type&&), front_insert_iterator<>:: (typename _Container::value_type&&), front_insert_iterator<>::
operator=(typename _Container::value_type&&), insert_iterator<>:: operator=(typename _Container::value_type&&), insert_iterator<>::
......
...@@ -353,6 +353,34 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -353,6 +353,34 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
}; };
#endif #endif
template<typename _Tp>
struct __is_byte
{
enum { __value = 0 };
typedef __false_type __type;
};
template<>
struct __is_byte<char>
{
enum { __value = 1 };
typedef __true_type __type;
};
template<>
struct __is_byte<signed char>
{
enum { __value = 1 };
typedef __true_type __type;
};
template<>
struct __is_byte<unsigned char>
{
enum { __value = 1 };
typedef __true_type __type;
};
_GLIBCXX_END_NAMESPACE _GLIBCXX_END_NAMESPACE
#endif //_CPP_TYPE_TRAITS_H #endif //_CPP_TYPE_TRAITS_H
...@@ -500,56 +500,32 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -500,56 +500,32 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
} }
template<bool> template<typename _ForwardIterator, typename _Tp>
struct __fill inline typename
{ __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value, void>::__type
template<typename _ForwardIterator, typename _Tp> __fill_a(_ForwardIterator __first, _ForwardIterator __last,
static void const _Tp& __value)
fill(_ForwardIterator __first, _ForwardIterator __last,
const _Tp& __value)
{
for (; __first != __last; ++__first)
*__first = __value;
}
};
template<>
struct __fill<true>
{ {
template<typename _ForwardIterator, typename _Tp> for (; __first != __last; ++__first)
static void *__first = __value;
fill(_ForwardIterator __first, _ForwardIterator __last, }
const _Tp& __value)
{
const _Tp __tmp = __value;
for (; __first != __last; ++__first)
*__first = __tmp;
}
};
template<typename _ForwardIterator, typename _Tp> template<typename _ForwardIterator, typename _Tp>
inline void inline typename
__fill_aux(_ForwardIterator __first, _ForwardIterator __last, __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, void>::__type
const _Tp& __value) __fill_a(_ForwardIterator __first, _ForwardIterator __last, _Tp __value)
{ {
const bool __scalar = __is_scalar<_Tp>::__value; for (; __first != __last; ++__first)
std::__fill<__scalar>::fill(__first, __last, __value); *__first = __value;
} }
// Specialization: for char types we can use memset. // Specialization: for char types we can use memset.
inline void template<typename _Tp>
__fill_aux(unsigned char* __first, unsigned char* __last, unsigned char __c) inline typename
{ __builtin_memset(__first, __c, __last - __first); } __gnu_cxx::__enable_if<__is_byte<_Tp>::__value, void>::__type
__fill_a(_Tp* __first, _Tp* __last, _Tp __c)
inline void { __builtin_memset(__first, static_cast<unsigned char>(__c),
__fill_aux(signed char* __first, signed char* __last, signed char __c) __last - __first); }
{ __builtin_memset(__first, static_cast<unsigned char>(__c),
__last - __first); }
inline void
__fill_aux(char* __first, char* __last, char __c)
{ __builtin_memset(__first, static_cast<unsigned char>(__c),
__last - __first); }
/** /**
* @brief Fills the range [first,last) with copies of value. * @brief Fills the range [first,last) with copies of value.
...@@ -571,66 +547,36 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -571,66 +547,36 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
_ForwardIterator>) _ForwardIterator>)
__glibcxx_requires_valid_range(__first, __last); __glibcxx_requires_valid_range(__first, __last);
std::__fill_aux(__niter_base<_ForwardIterator>::__b(__first), std::__fill_a(std::__niter_base<_ForwardIterator>::__b(__first),
__niter_base<_ForwardIterator>::__b(__last), __value); std::__niter_base<_ForwardIterator>::__b(__last), __value);
} }
template<bool>
struct __fill_n
{
template<typename _OutputIterator, typename _Size, typename _Tp>
static _OutputIterator
fill_n(_OutputIterator __first, _Size __n, const _Tp& __value)
{
for (; __n > 0; --__n, ++__first)
*__first = __value;
return __first;
}
};
template<>
struct __fill_n<true>
{
template<typename _OutputIterator, typename _Size, typename _Tp>
static _OutputIterator
fill_n(_OutputIterator __first, _Size __n, const _Tp& __value)
{
const _Tp __tmp = __value;
for (; __n > 0; --__n, ++__first)
*__first = __tmp;
return __first;
}
};
template<typename _OutputIterator, typename _Size, typename _Tp> template<typename _OutputIterator, typename _Size, typename _Tp>
inline _OutputIterator inline typename
__fill_n_aux(_OutputIterator __first, _Size __n, const _Tp& __value) __gnu_cxx::__enable_if<!__is_scalar<_Tp>::__value, _OutputIterator>::__type
{ __fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value)
const bool __scalar = __is_scalar<_Tp>::__value;
return std::__fill_n<__scalar>::fill_n(__first, __n, __value);
}
template<typename _Size>
inline unsigned char*
__fill_n_aux(unsigned char* __first, _Size __n, unsigned char __c)
{ {
std::__fill_aux(__first, __first + __n, __c); for (; __n > 0; --__n, ++__first)
return __first + __n; *__first = __value;
return __first;
} }
template<typename _Size> template<typename _OutputIterator, typename _Size, typename _Tp>
inline signed char* inline typename
__fill_n_aux(signed char* __first, _Size __n, signed char __c) __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, _OutputIterator>::__type
__fill_n_a(_OutputIterator __first, _Size __n, _Tp __value)
{ {
std::__fill_aux(__first, __first + __n, __c); for (; __n > 0; --__n, ++__first)
return __first + __n; *__first = __value;
return __first;
} }
template<typename _Size> template<typename _Size, typename _Tp>
inline char* inline typename
__fill_n_aux(char* __first, _Size __n, char __c) __gnu_cxx::__enable_if<__is_byte<_Tp>::__value, _Tp*>::__type
__fill_n_a(_Tp* __first, _Size __n, _Tp __c)
{ {
std::__fill_aux(__first, __first + __n, __c); std::__fill_a(__first, __first + __n, __c);
return __first + __n; return __first + __n;
} }
...@@ -652,8 +598,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -652,8 +598,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
// concept requirements // concept requirements
__glibcxx_function_requires(_OutputIteratorConcept<_OI, _Tp>) __glibcxx_function_requires(_OutputIteratorConcept<_OI, _Tp>)
return _OI(std::__fill_n_aux(__niter_base<_OI>::__b(__first), __n, return _OI(std::__fill_n_a(std::__niter_base<_OI>::__b(__first),
__value)); __n, __value));
} }
template<bool _BoolType> template<bool _BoolType>
...@@ -803,9 +749,9 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_P) ...@@ -803,9 +749,9 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_P)
typename iterator_traits<_II2>::value_type>) typename iterator_traits<_II2>::value_type>)
__glibcxx_requires_valid_range(__first1, __last1); __glibcxx_requires_valid_range(__first1, __last1);
return std::__equal_aux(__niter_base<_II1>::__b(__first1), return std::__equal_aux(std::__niter_base<_II1>::__b(__first1),
__niter_base<_II1>::__b(__last1), std::__niter_base<_II1>::__b(__last1),
__niter_base<_II2>::__b(__first2)); std::__niter_base<_II2>::__b(__first2));
} }
/** /**
......
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