Commit 5e91e92e by Paolo Carlini Committed by Paolo Carlini

type_traits.h (_Is_normal_iterator): Move...

2004-07-02  Paolo Carlini  <pcarlini@suse.de>

	* 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
parent ec13a3ef
2004-07-02 Paolo Carlini <pcarlini@suse.de>
* 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 <pcarlini@suse.de> 2004-07-01 Paolo Carlini <pcarlini@suse.de>
* include/bits/stl_algobase.h (__copy_trivial): Remove. * include/bits/stl_algobase.h (__copy_trivial): Remove.
......
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
// //
// This file provides some compile-time information about various types. // This file provides some compile-time information about various types.
// These representations were designed, on purpose, to be constant-expressions // These representations were designed, on purpose, to be constant-expressions
// and not types as found in <stl/bits/type_traits.h>. In particular, they // and not types as found in <bits/type_traits.h>. In particular, they
// can be used in control structures and the optimizer hopefully will do // can be used in control structures and the optimizer hopefully will do
// the obvious thing. // the obvious thing.
// //
...@@ -77,6 +77,13 @@ namespace __gnu_internal ...@@ -77,6 +77,13 @@ namespace __gnu_internal
__two& __test_type (...); __two& __test_type (...);
} // namespace __gnu_internal } // namespace __gnu_internal
// Forward declaration hack, should really include this from somewhere.
namespace __gnu_cxx
{
template<typename _Iterator, typename _Container>
class __normal_iterator;
} // namespace __gnu_cxx
namespace std namespace std
{ {
// Compare for equality of types. // Compare for equality of types.
...@@ -325,6 +332,28 @@ namespace std ...@@ -325,6 +332,28 @@ namespace std
}; };
// //
// Normal iterator type
//
template<typename _Tp>
struct __is_normal_iterator
{
enum
{
_M_type = 0
};
};
template<typename _Iterator, typename _Container>
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 // An arithmetic type is an integer type or a floating point type
// //
template<typename _Tp> template<typename _Tp>
......
...@@ -66,10 +66,8 @@ ...@@ -66,10 +66,8 @@
#include <climits> #include <climits>
#include <cstdlib> #include <cstdlib>
#include <cstddef> #include <cstddef>
#include <new>
#include <iosfwd> #include <iosfwd>
#include <bits/stl_pair.h> #include <bits/stl_pair.h>
#include <bits/type_traits.h>
#include <bits/cpp_type_traits.h> #include <bits/cpp_type_traits.h>
#include <bits/stl_iterator_base_types.h> #include <bits/stl_iterator_base_types.h>
#include <bits/stl_iterator_base_funcs.h> #include <bits/stl_iterator_base_funcs.h>
...@@ -220,7 +218,7 @@ namespace std ...@@ -220,7 +218,7 @@ namespace std
return __a; 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, // calls to copy with memmove whenever possible. (Memmove, not memcpy,
// because the input and output ranges are permitted to overlap.) // because the input and output ranges are permitted to overlap.)
// (2) If we're using random access iterators, then write the loop as // (2) If we're using random access iterators, then write the loop as
...@@ -276,7 +274,7 @@ namespace std ...@@ -276,7 +274,7 @@ namespace std
typedef typename iterator_traits<_II>::value_type _ValueTypeI; typedef typename iterator_traits<_II>::value_type _ValueTypeI;
typedef typename iterator_traits<_OI>::value_type _ValueTypeO; typedef typename iterator_traits<_OI>::value_type _ValueTypeO;
typedef typename iterator_traits<_II>::iterator_category _Category; 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<_II>::_M_type
&& __is_pointer<_OI>::_M_type && __is_pointer<_OI>::_M_type
&& __are_same<_ValueTypeI, _ValueTypeO>::_M_type); && __are_same<_ValueTypeI, _ValueTypeO>::_M_type);
...@@ -284,37 +282,42 @@ namespace std ...@@ -284,37 +282,42 @@ namespace std
return std::__copy<__simple, _Category>::copy(__first, __last, __result); return std::__copy<__simple, _Category>::copy(__first, __last, __result);
} }
template<typename _InputIterator, typename _OutputIterator> template<bool, bool>
inline _OutputIterator struct __copy_normal
__copy_ni2(_InputIterator __first, _InputIterator __last, {
_OutputIterator __result, __true_type) template<typename _II, typename _OI>
{ return _OutputIterator(std::__copy_aux(__first, __last, static _OI
__result.base())); } copy_n(_II __first, _II __last, _OI __result)
{ return std::__copy_aux(__first, __last, __result); }
};
template<typename _InputIterator, typename _OutputIterator> template<>
inline _OutputIterator struct __copy_normal<true, false>
__copy_ni2(_InputIterator __first, _InputIterator __last, {
_OutputIterator __result, __false_type) template<typename _II, typename _OI>
{ return std::__copy_aux(__first, __last, __result); } static _OI
copy_n(_II __first, _II __last, _OI __result)
{ return std::__copy_aux(__first.base(), __last.base(), __result); }
};
template<typename _InputIterator, typename _OutputIterator> template<>
inline _OutputIterator struct __copy_normal<false, true>
__copy_ni1(_InputIterator __first, _InputIterator __last,
_OutputIterator __result, __true_type)
{ {
typedef typename _Is_normal_iterator<_OutputIterator>::_Normal __Normal; template<typename _II, typename _OI>
return std::__copy_ni2(__first.base(), __last.base(), static _OI
__result, __Normal()); copy_n(_II __first, _II __last, _OI __result)
} { return _OI(std::__copy_aux(__first, __last, __result.base())); }
};
template<typename _InputIterator, typename _OutputIterator> template<>
inline _OutputIterator struct __copy_normal<true, true>
__copy_ni1(_InputIterator __first, _InputIterator __last,
_OutputIterator __result, __false_type)
{ {
typedef typename _Is_normal_iterator<_OutputIterator>::_Normal __Normal; template<typename _II, typename _OI>
return std::__copy_ni2(__first, __last, __result, __Normal()); 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. * @brief Copies the range [first,last) into result.
...@@ -343,8 +346,10 @@ namespace std ...@@ -343,8 +346,10 @@ namespace std
typename iterator_traits<_InputIterator>::value_type>) typename iterator_traits<_InputIterator>::value_type>)
__glibcxx_requires_valid_range(__first, __last); __glibcxx_requires_valid_range(__first, __last);
typedef typename _Is_normal_iterator<_InputIterator>::_Normal __Normal; const bool __in = __is_normal_iterator<_InputIterator>::_M_type;
return std::__copy_ni1(__first, __last, __result, __Normal()); const bool __out = __is_normal_iterator<_OutputIterator>::_M_type;
return std::__copy_normal<__in, __out>::copy_n(__first, __last,
__result);
} }
template<bool, typename> template<bool, typename>
...@@ -394,7 +399,7 @@ namespace std ...@@ -394,7 +399,7 @@ namespace std
typedef typename iterator_traits<_BI1>::value_type _ValueType1; typedef typename iterator_traits<_BI1>::value_type _ValueType1;
typedef typename iterator_traits<_BI2>::value_type _ValueType2; typedef typename iterator_traits<_BI2>::value_type _ValueType2;
typedef typename iterator_traits<_BI1>::iterator_category _Category; 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<_BI1>::_M_type
&& __is_pointer<_BI2>::_M_type && __is_pointer<_BI2>::_M_type
&& __are_same<_ValueType1, _ValueType2>::_M_type); && __are_same<_ValueType1, _ValueType2>::_M_type);
...@@ -403,38 +408,44 @@ namespace std ...@@ -403,38 +408,44 @@ namespace std
__result); __result);
} }
template <typename _BI1, typename _BI2> template<bool, bool>
inline _BI2 struct __copy_backward_normal
__copy_backward_output_normal_iterator(_BI1 __first, _BI1 __last, {
_BI2 __result, __true_type) template<typename _BI1, typename _BI2>
{ return _BI2(std::__copy_backward_aux(__first, __last, __result.base())); } static _BI2
copy_b_n(_BI1 __first, _BI1 __last, _BI2 __result)
{ return std::__copy_backward_aux(__first, __last, __result); }
};
template <typename _BI1, typename _BI2> template<>
inline _BI2 struct __copy_backward_normal<true, false>
__copy_backward_output_normal_iterator(_BI1 __first, _BI1 __last, {
_BI2 __result, __false_type) template<typename _BI1, typename _BI2>
{ return std::__copy_backward_aux(__first, __last, __result); } static _BI2
copy_b_n(_BI1 __first, _BI1 __last, _BI2 __result)
{ return std::__copy_backward_aux(__first.base(), __last.base(),
__result); }
};
template <typename _BI1, typename _BI2> template<>
inline _BI2 struct __copy_backward_normal<false, true>
__copy_backward_input_normal_iterator(_BI1 __first, _BI1 __last,
_BI2 __result, __true_type)
{ {
typedef typename _Is_normal_iterator<_BI2>::_Normal __Normal; template<typename _BI1, typename _BI2>
return std::__copy_backward_output_normal_iterator(__first.base(), static _BI2
__last.base(), copy_b_n(_BI1 __first, _BI1 __last, _BI2 __result)
__result, __Normal()); { return _BI2(std::__copy_backward_aux(__first, __last,
} __result.base())); }
};
template <typename _BI1, typename _BI2> template<>
inline _BI2 struct __copy_backward_normal<true, true>
__copy_backward_input_normal_iterator(_BI1 __first, _BI1 __last,
_BI2 __result, __false_type)
{ {
typedef typename _Is_normal_iterator<_BI2>::_Normal __Normal; template<typename _BI1, typename _BI2>
return std::__copy_backward_output_normal_iterator(__first, __last, static _BI2
__result, __Normal()); 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. * @brief Copies the range [first,last) into result.
...@@ -465,9 +476,10 @@ namespace std ...@@ -465,9 +476,10 @@ namespace std
typename iterator_traits<_BI2>::value_type>) typename iterator_traits<_BI2>::value_type>)
__glibcxx_requires_valid_range(__first, __last); __glibcxx_requires_valid_range(__first, __last);
typedef typename _Is_normal_iterator<_BI1>::_Normal __Normal; const bool __bi1 = __is_normal_iterator<_BI1>::_M_type;
return std::__copy_backward_input_normal_iterator(__first, __last, const bool __bi2 = __is_normal_iterator<_BI2>::_M_type;
__result, __Normal()); return std::__copy_backward_normal<__bi1, __bi2>::copy_b_n(__first, __last,
__result);
} }
template<bool> template<bool>
......
...@@ -378,26 +378,6 @@ template<> ...@@ -378,26 +378,6 @@ template<>
typedef __true_type _Integral; typedef __true_type _Integral;
}; };
template<typename _Tp>
struct _Is_normal_iterator
{
typedef __false_type _Normal;
};
// Forward declaration hack, should really include this from somewhere.
namespace __gnu_cxx
{
template<typename _Iterator, typename _Container>
class __normal_iterator;
}
template<typename _Iterator, typename _Container>
struct _Is_normal_iterator< __gnu_cxx::__normal_iterator<_Iterator,
_Container> >
{
typedef __true_type _Normal;
};
#endif /* _TYPE_TRAITS_H */ #endif /* _TYPE_TRAITS_H */
// Local Variables: // Local Variables:
......
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