From 394033f804beb1128fd78b24ba21db2bbc790b00 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Wed, 17 Oct 2007 21:21:13 +0000 Subject: [PATCH] cpp_type_traits.h (__is_byte): Add. 2007-10-17 Paolo Carlini * 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 --- libstdc++-v3/ChangeLog | 8 ++ libstdc++-v3/include/bits/cpp_type_traits.h | 28 ++++ libstdc++-v3/include/bits/stl_algobase.h | 144 ++++++-------------- 3 files changed, 81 insertions(+), 99 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 05a21602909..91db12e18de 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,11 @@ +2007-10-17 Paolo Carlini + + * 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 * include/bits/stl_iterator.h (back_insert_iterator<>::operator= diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h b/libstdc++-v3/include/bits/cpp_type_traits.h index f3c71ac1be5..4948f6c8d85 100644 --- a/libstdc++-v3/include/bits/cpp_type_traits.h +++ b/libstdc++-v3/include/bits/cpp_type_traits.h @@ -353,6 +353,34 @@ _GLIBCXX_BEGIN_NAMESPACE(std) }; #endif + template + struct __is_byte + { + enum { __value = 0 }; + typedef __false_type __type; + }; + + template<> + struct __is_byte + { + enum { __value = 1 }; + typedef __true_type __type; + }; + + template<> + struct __is_byte + { + enum { __value = 1 }; + typedef __true_type __type; + }; + + template<> + struct __is_byte + { + enum { __value = 1 }; + typedef __true_type __type; + }; + _GLIBCXX_END_NAMESPACE #endif //_CPP_TYPE_TRAITS_H diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h index c641df513a6..55c0eb24e50 100644 --- a/libstdc++-v3/include/bits/stl_algobase.h +++ b/libstdc++-v3/include/bits/stl_algobase.h @@ -500,56 +500,32 @@ _GLIBCXX_BEGIN_NAMESPACE(std) } - template - struct __fill - { - template - static void - fill(_ForwardIterator __first, _ForwardIterator __last, - const _Tp& __value) - { - for (; __first != __last; ++__first) - *__first = __value; - } - }; - - template<> - struct __fill + template + inline typename + __gnu_cxx::__enable_if::__value, void>::__type + __fill_a(_ForwardIterator __first, _ForwardIterator __last, + const _Tp& __value) { - template - static void - fill(_ForwardIterator __first, _ForwardIterator __last, - const _Tp& __value) - { - const _Tp __tmp = __value; - for (; __first != __last; ++__first) - *__first = __tmp; - } - }; - + for (; __first != __last; ++__first) + *__first = __value; + } + template - inline void - __fill_aux(_ForwardIterator __first, _ForwardIterator __last, - const _Tp& __value) + inline typename + __gnu_cxx::__enable_if<__is_scalar<_Tp>::__value, void>::__type + __fill_a(_ForwardIterator __first, _ForwardIterator __last, _Tp __value) { - const bool __scalar = __is_scalar<_Tp>::__value; - std::__fill<__scalar>::fill(__first, __last, __value); + for (; __first != __last; ++__first) + *__first = __value; } // Specialization: for char types we can use memset. - inline void - __fill_aux(unsigned char* __first, unsigned char* __last, unsigned char __c) - { __builtin_memset(__first, __c, __last - __first); } - - inline void - __fill_aux(signed char* __first, signed char* __last, signed char __c) - { __builtin_memset(__first, static_cast(__c), - __last - __first); } - - inline void - __fill_aux(char* __first, char* __last, char __c) - { __builtin_memset(__first, static_cast(__c), - __last - __first); } + template + inline typename + __gnu_cxx::__enable_if<__is_byte<_Tp>::__value, void>::__type + __fill_a(_Tp* __first, _Tp* __last, _Tp __c) + { __builtin_memset(__first, static_cast(__c), + __last - __first); } /** * @brief Fills the range [first,last) with copies of value. @@ -571,66 +547,36 @@ _GLIBCXX_BEGIN_NAMESPACE(std) _ForwardIterator>) __glibcxx_requires_valid_range(__first, __last); - std::__fill_aux(__niter_base<_ForwardIterator>::__b(__first), - __niter_base<_ForwardIterator>::__b(__last), __value); + std::__fill_a(std::__niter_base<_ForwardIterator>::__b(__first), + std::__niter_base<_ForwardIterator>::__b(__last), __value); } - template - struct __fill_n - { - template - static _OutputIterator - fill_n(_OutputIterator __first, _Size __n, const _Tp& __value) - { - for (; __n > 0; --__n, ++__first) - *__first = __value; - return __first; - } - }; - - template<> - struct __fill_n - { - template - 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 - inline _OutputIterator - __fill_n_aux(_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 - inline unsigned char* - __fill_n_aux(unsigned char* __first, _Size __n, unsigned char __c) + inline typename + __gnu_cxx::__enable_if::__value, _OutputIterator>::__type + __fill_n_a(_OutputIterator __first, _Size __n, const _Tp& __value) { - std::__fill_aux(__first, __first + __n, __c); - return __first + __n; + for (; __n > 0; --__n, ++__first) + *__first = __value; + return __first; } - template - inline signed char* - __fill_n_aux(signed char* __first, _Size __n, signed char __c) + template + inline typename + __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); - return __first + __n; + for (; __n > 0; --__n, ++__first) + *__first = __value; + return __first; } - template - inline char* - __fill_n_aux(char* __first, _Size __n, char __c) + template + inline typename + __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; } @@ -652,8 +598,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std) // concept requirements __glibcxx_function_requires(_OutputIteratorConcept<_OI, _Tp>) - return _OI(std::__fill_n_aux(__niter_base<_OI>::__b(__first), __n, - __value)); + return _OI(std::__fill_n_a(std::__niter_base<_OI>::__b(__first), + __n, __value)); } template @@ -803,9 +749,9 @@ _GLIBCXX_BEGIN_NESTED_NAMESPACE(std, _GLIBCXX_STD_P) typename iterator_traits<_II2>::value_type>) __glibcxx_requires_valid_range(__first1, __last1); - return std::__equal_aux(__niter_base<_II1>::__b(__first1), - __niter_base<_II1>::__b(__last1), - __niter_base<_II2>::__b(__first2)); + return std::__equal_aux(std::__niter_base<_II1>::__b(__first1), + std::__niter_base<_II1>::__b(__last1), + std::__niter_base<_II2>::__b(__first2)); } /** -- 2.30.2