From: Paolo Carlini Date: Fri, 2 Jul 2004 14:49:09 +0000 (+0000) Subject: type_traits.h (_Is_normal_iterator): Move... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=5e91e92ede69d69e331a6acac2502a69e4a5abb6;p=gcc.git type_traits.h (_Is_normal_iterator): Move... 2004-07-02 Paolo Carlini * include/bits/type_traits.h (_Is_normal_iterator): Move... * include/bits/cpp_type_traits.h: ... here, renamed to __is_normal_iterator and consistent with the other traits. * include/bits/stl_algobase.h (__copy_ni1, __copy_ni2): Convert to the struct __copy_normal and three specializations. (__copy_backward_output_normal_iterator, __copy_backward_input_normal_iterator): Likewise, convert to the struct __copy_backward_normal and three specializations. (copy, copy_backward): Use the latter. (__copy_aux, __copy_backward_aux): Very minor tweaks. From-SVN: r84019 --- diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index f981c0f1ca6..4a28639dd98 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,16 @@ +2004-07-02 Paolo Carlini + + * include/bits/type_traits.h (_Is_normal_iterator): Move... + * include/bits/cpp_type_traits.h: ... here, renamed to + __is_normal_iterator and consistent with the other traits. + * include/bits/stl_algobase.h (__copy_ni1, __copy_ni2): Convert + to the struct __copy_normal and three specializations. + (__copy_backward_output_normal_iterator, + __copy_backward_input_normal_iterator): Likewise, convert to + the struct __copy_backward_normal and three specializations. + (copy, copy_backward): Use the latter. + (__copy_aux, __copy_backward_aux): Very minor tweaks. + 2004-07-01 Paolo Carlini * include/bits/stl_algobase.h (__copy_trivial): Remove. diff --git a/libstdc++-v3/include/bits/cpp_type_traits.h b/libstdc++-v3/include/bits/cpp_type_traits.h index bf9254fd204..feb7b1c93e8 100644 --- a/libstdc++-v3/include/bits/cpp_type_traits.h +++ b/libstdc++-v3/include/bits/cpp_type_traits.h @@ -42,7 +42,7 @@ // // This file provides some compile-time information about various types. // These representations were designed, on purpose, to be constant-expressions -// and not types as found in . In particular, they +// and not types as found in . In particular, they // can be used in control structures and the optimizer hopefully will do // the obvious thing. // @@ -77,6 +77,13 @@ namespace __gnu_internal __two& __test_type (...); } // namespace __gnu_internal +// Forward declaration hack, should really include this from somewhere. +namespace __gnu_cxx +{ + template + class __normal_iterator; +} // namespace __gnu_cxx + namespace std { // Compare for equality of types. @@ -324,6 +331,28 @@ namespace std }; }; + // + // Normal iterator type + // + template + struct __is_normal_iterator + { + enum + { + _M_type = 0 + }; + }; + + template + struct __is_normal_iterator< __gnu_cxx::__normal_iterator<_Iterator, + _Container> > + { + enum + { + _M_type = 1 + }; + }; + // // An arithmetic type is an integer type or a floating point type // diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h index 1b441e0a6d4..39a52ca1812 100644 --- a/libstdc++-v3/include/bits/stl_algobase.h +++ b/libstdc++-v3/include/bits/stl_algobase.h @@ -66,10 +66,8 @@ #include #include #include -#include #include #include -#include #include #include #include @@ -220,7 +218,7 @@ namespace std return __a; } - // All of these auxiliary functions serve two purposes. (1) Replace + // All of these auxiliary structs serve two purposes. (1) Replace // calls to copy with memmove whenever possible. (Memmove, not memcpy, // because the input and output ranges are permitted to overlap.) // (2) If we're using random access iterators, then write the loop as @@ -276,7 +274,7 @@ namespace std typedef typename iterator_traits<_II>::value_type _ValueTypeI; typedef typename iterator_traits<_OI>::value_type _ValueTypeO; typedef typename iterator_traits<_II>::iterator_category _Category; - const bool __simple = (__is_trivially_copyable<_ValueTypeO>::_M_type + const bool __simple = (__is_trivially_copyable<_ValueTypeI>::_M_type && __is_pointer<_II>::_M_type && __is_pointer<_OI>::_M_type && __are_same<_ValueTypeI, _ValueTypeO>::_M_type); @@ -284,37 +282,42 @@ namespace std return std::__copy<__simple, _Category>::copy(__first, __last, __result); } - template - inline _OutputIterator - __copy_ni2(_InputIterator __first, _InputIterator __last, - _OutputIterator __result, __true_type) - { return _OutputIterator(std::__copy_aux(__first, __last, - __result.base())); } + template + struct __copy_normal + { + template + static _OI + copy_n(_II __first, _II __last, _OI __result) + { return std::__copy_aux(__first, __last, __result); } + }; - template - inline _OutputIterator - __copy_ni2(_InputIterator __first, _InputIterator __last, - _OutputIterator __result, __false_type) - { return std::__copy_aux(__first, __last, __result); } + template<> + struct __copy_normal + { + template + static _OI + copy_n(_II __first, _II __last, _OI __result) + { return std::__copy_aux(__first.base(), __last.base(), __result); } + }; - template - inline _OutputIterator - __copy_ni1(_InputIterator __first, _InputIterator __last, - _OutputIterator __result, __true_type) + template<> + struct __copy_normal { - typedef typename _Is_normal_iterator<_OutputIterator>::_Normal __Normal; - return std::__copy_ni2(__first.base(), __last.base(), - __result, __Normal()); - } + template + static _OI + copy_n(_II __first, _II __last, _OI __result) + { return _OI(std::__copy_aux(__first, __last, __result.base())); } + }; - template - inline _OutputIterator - __copy_ni1(_InputIterator __first, _InputIterator __last, - _OutputIterator __result, __false_type) + template<> + struct __copy_normal { - typedef typename _Is_normal_iterator<_OutputIterator>::_Normal __Normal; - return std::__copy_ni2(__first, __last, __result, __Normal()); - } + template + static _OI + copy_n(_II __first, _II __last, _OI __result) + { return _OI(std::__copy_aux(__first.base(), __last.base(), + __result.base())); } + }; /** * @brief Copies the range [first,last) into result. @@ -343,8 +346,10 @@ namespace std typename iterator_traits<_InputIterator>::value_type>) __glibcxx_requires_valid_range(__first, __last); - typedef typename _Is_normal_iterator<_InputIterator>::_Normal __Normal; - return std::__copy_ni1(__first, __last, __result, __Normal()); + const bool __in = __is_normal_iterator<_InputIterator>::_M_type; + const bool __out = __is_normal_iterator<_OutputIterator>::_M_type; + return std::__copy_normal<__in, __out>::copy_n(__first, __last, + __result); } template @@ -394,7 +399,7 @@ namespace std typedef typename iterator_traits<_BI1>::value_type _ValueType1; typedef typename iterator_traits<_BI2>::value_type _ValueType2; typedef typename iterator_traits<_BI1>::iterator_category _Category; - const bool __simple = (__is_trivially_copyable<_ValueType2>::_M_type + const bool __simple = (__is_trivially_copyable<_ValueType1>::_M_type && __is_pointer<_BI1>::_M_type && __is_pointer<_BI2>::_M_type && __are_same<_ValueType1, _ValueType2>::_M_type); @@ -403,38 +408,44 @@ namespace std __result); } - template - inline _BI2 - __copy_backward_output_normal_iterator(_BI1 __first, _BI1 __last, - _BI2 __result, __true_type) - { return _BI2(std::__copy_backward_aux(__first, __last, __result.base())); } + template + struct __copy_backward_normal + { + template + static _BI2 + copy_b_n(_BI1 __first, _BI1 __last, _BI2 __result) + { return std::__copy_backward_aux(__first, __last, __result); } + }; - template - inline _BI2 - __copy_backward_output_normal_iterator(_BI1 __first, _BI1 __last, - _BI2 __result, __false_type) - { return std::__copy_backward_aux(__first, __last, __result); } + template<> + struct __copy_backward_normal + { + template + static _BI2 + copy_b_n(_BI1 __first, _BI1 __last, _BI2 __result) + { return std::__copy_backward_aux(__first.base(), __last.base(), + __result); } + }; - template - inline _BI2 - __copy_backward_input_normal_iterator(_BI1 __first, _BI1 __last, - _BI2 __result, __true_type) + template<> + struct __copy_backward_normal { - typedef typename _Is_normal_iterator<_BI2>::_Normal __Normal; - return std::__copy_backward_output_normal_iterator(__first.base(), - __last.base(), - __result, __Normal()); - } + template + static _BI2 + copy_b_n(_BI1 __first, _BI1 __last, _BI2 __result) + { return _BI2(std::__copy_backward_aux(__first, __last, + __result.base())); } + }; - template - inline _BI2 - __copy_backward_input_normal_iterator(_BI1 __first, _BI1 __last, - _BI2 __result, __false_type) + template<> + struct __copy_backward_normal { - typedef typename _Is_normal_iterator<_BI2>::_Normal __Normal; - return std::__copy_backward_output_normal_iterator(__first, __last, - __result, __Normal()); - } + template + static _BI2 + copy_b_n(_BI1 __first, _BI1 __last, _BI2 __result) + { return _BI2(std::__copy_backward_aux(__first.base(), __last.base(), + __result.base())); } + }; /** * @brief Copies the range [first,last) into result. @@ -465,9 +476,10 @@ namespace std typename iterator_traits<_BI2>::value_type>) __glibcxx_requires_valid_range(__first, __last); - typedef typename _Is_normal_iterator<_BI1>::_Normal __Normal; - return std::__copy_backward_input_normal_iterator(__first, __last, - __result, __Normal()); + const bool __bi1 = __is_normal_iterator<_BI1>::_M_type; + const bool __bi2 = __is_normal_iterator<_BI2>::_M_type; + return std::__copy_backward_normal<__bi1, __bi2>::copy_b_n(__first, __last, + __result); } template diff --git a/libstdc++-v3/include/bits/type_traits.h b/libstdc++-v3/include/bits/type_traits.h index 9b91e5c5cdf..0a263e5e0b6 100644 --- a/libstdc++-v3/include/bits/type_traits.h +++ b/libstdc++-v3/include/bits/type_traits.h @@ -378,26 +378,6 @@ template<> typedef __true_type _Integral; }; -template - struct _Is_normal_iterator - { - typedef __false_type _Normal; - }; - -// Forward declaration hack, should really include this from somewhere. -namespace __gnu_cxx -{ - template - class __normal_iterator; -} - -template - struct _Is_normal_iterator< __gnu_cxx::__normal_iterator<_Iterator, - _Container> > - { - typedef __true_type _Normal; - }; - #endif /* _TYPE_TRAITS_H */ // Local Variables: