This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
[Patch] Start using the front-end traits in the library
- From: Paolo Carlini <pcarlini at suse dot de>
- To: libstdc++ <libstdc++ at gcc dot gnu dot org>
- Date: Mon, 02 Apr 2007 20:53:53 +0200
- Subject: [Patch] Start using the front-end traits in the library
Hi,
these are the first bits (besided those parts of the big C++ patch),
using the traits for the implementation of the C++03 library. Actually,
only __is_pod and __has_trivial_destructor are exploited, among the most
straightforward.
Tested x86/x86-64-linux.
Paolo.
//////////////
2007-04-03 Paolo Carlini <pcarlini@suse.de>
* include/bits/stl_algobase.h (__copy_aux(_II, _II, _OI),
__copy_backward_aux(_BI1, _BI1, _BI2)): Use __is_pod.
* include/bits/stl_deque.h (deque<>::_M_destroy_data(iterator,
iterator, const std::allocator<>&)): Use __has_trivial_constructor.
(deque<>::_M_destroy_data_dispatch): Remove.
* include/bits/stl_uninitialized.h (uninitialized_copy(_InputIterator,
_InputIterator, _ForwardIterator), uninitialized_fill(_ForwardIterator,
_ForwardIterator, const _Tp&), uninitialized_fill_n(_ForwardIterator,
_Size, const _Tp&)): Use __is_pod.
* include/bits/stl_tempbuf.h (_Temporary_buffer::
_Temporary_buffer(_ForwardIterator, _ForwardIterator)): Use __is_pod.
(_Temporary_buffer::_M_initialize_buffer): Remove.
* include/bits/stl_construct.h (_Destroy(_ForwardIterator,
_ForwardIterator)): Use __has_trivial_destructor.
(__destroy_aux): Remove.
Index: include/bits/stl_algobase.h
===================================================================
--- include/bits/stl_algobase.h (revision 123431)
+++ include/bits/stl_algobase.h (working copy)
@@ -341,7 +341,7 @@
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_scalar<_ValueTypeI>::__value
+ const bool __simple = (__is_pod(_ValueTypeI)
&& __is_pointer<_II>::__value
&& __is_pointer<_OI>::__value
&& __are_same<_ValueTypeI, _ValueTypeO>::__value);
@@ -495,7 +495,7 @@
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_scalar<_ValueType1>::__value
+ const bool __simple = (__is_pod(_ValueType1)
&& __is_pointer<_BI1>::__value
&& __is_pointer<_BI2>::__value
&& __are_same<_ValueType1, _ValueType2>::__value);
Index: include/bits/stl_deque.h
===================================================================
--- include/bits/stl_deque.h (revision 123420)
+++ include/bits/stl_deque.h (working copy)
@@ -1,6 +1,6 @@
// Deque implementation -*- C++ -*-
-// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006
+// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007
// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
@@ -1424,13 +1424,6 @@
void
_M_destroy_data_aux(iterator __first, iterator __last);
- void
- _M_destroy_data_dispatch(iterator, iterator, __true_type) { }
-
- void
- _M_destroy_data_dispatch(iterator __first, iterator __last, __false_type)
- { _M_destroy_data_aux(__first, __last); }
-
// Called by ~deque().
// NB: Doesn't deallocate the nodes.
template<typename _Alloc1>
@@ -1442,9 +1435,8 @@
_M_destroy_data(iterator __first, iterator __last,
const std::allocator<_Tp>&)
{
- typedef typename std::__is_scalar<value_type>::__type
- _Has_trivial_destructor;
- _M_destroy_data_dispatch(__first, __last, _Has_trivial_destructor());
+ if (!__has_trivial_destructor(value_type))
+ _M_destroy_data_aux(__first, __last);
}
// Called by erase(q1, q2).
Index: include/bits/stl_uninitialized.h
===================================================================
--- include/bits/stl_uninitialized.h (revision 123420)
+++ include/bits/stl_uninitialized.h (working copy)
@@ -64,19 +64,11 @@
_GLIBCXX_BEGIN_NAMESPACE(std)
- // uninitialized_copy
template<typename _InputIterator, typename _ForwardIterator>
- inline _ForwardIterator
- __uninitialized_copy_aux(_InputIterator __first, _InputIterator __last,
- _ForwardIterator __result,
- __true_type)
- { return std::copy(__first, __last, __result); }
-
- template<typename _InputIterator, typename _ForwardIterator>
- inline _ForwardIterator
- __uninitialized_copy_aux(_InputIterator __first, _InputIterator __last,
- _ForwardIterator __result,
- __false_type)
+ _ForwardIterator
+ __uninitialized_copy_aux(_InputIterator __first,
+ _InputIterator __last,
+ _ForwardIterator __result)
{
_ForwardIterator __cur = __result;
try
@@ -106,25 +98,20 @@
uninitialized_copy(_InputIterator __first, _InputIterator __last,
_ForwardIterator __result)
{
- typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType;
- typedef typename std::__is_scalar<_ValueType>::__type _Is_POD;
- return std::__uninitialized_copy_aux(__first, __last, __result,
- _Is_POD());
+ typedef typename iterator_traits<_ForwardIterator>::value_type
+ _ValueType;
+ if (__is_pod(_ValueType))
+ return std::copy(__first, __last, __result);
+ else
+ return std::__uninitialized_copy_aux(__first, __last, __result);
}
- // Valid if copy construction is equivalent to assignment, and if the
- // destructor is trivial.
- template<typename _ForwardIterator, typename _Tp>
- inline void
- __uninitialized_fill_aux(_ForwardIterator __first,
- _ForwardIterator __last,
- const _Tp& __x, __true_type)
- { std::fill(__first, __last, __x); }
template<typename _ForwardIterator, typename _Tp>
void
- __uninitialized_fill_aux(_ForwardIterator __first, _ForwardIterator __last,
- const _Tp& __x, __false_type)
+ __uninitialized_fill_aux(_ForwardIterator __first,
+ _ForwardIterator __last,
+ const _Tp& __x)
{
_ForwardIterator __cur = __first;
try
@@ -153,23 +140,19 @@
uninitialized_fill(_ForwardIterator __first, _ForwardIterator __last,
const _Tp& __x)
{
- typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType;
- typedef typename std::__is_scalar<_ValueType>::__type _Is_POD;
- std::__uninitialized_fill_aux(__first, __last, __x, _Is_POD());
+ typedef typename iterator_traits<_ForwardIterator>::value_type
+ _ValueType;
+ if (__is_pod(_ValueType))
+ std::fill(__first, __last, __x);
+ else
+ std::__uninitialized_fill_aux(__first, __last, __x);
}
- // Valid if copy construction is equivalent to assignment, and if the
- // destructor is trivial.
- template<typename _ForwardIterator, typename _Size, typename _Tp>
- inline void
- __uninitialized_fill_n_aux(_ForwardIterator __first, _Size __n,
- const _Tp& __x, __true_type)
- { std::fill_n(__first, __n, __x); }
template<typename _ForwardIterator, typename _Size, typename _Tp>
void
__uninitialized_fill_n_aux(_ForwardIterator __first, _Size __n,
- const _Tp& __x, __false_type)
+ const _Tp& __x)
{
_ForwardIterator __cur = __first;
try
@@ -197,9 +180,12 @@
inline void
uninitialized_fill_n(_ForwardIterator __first, _Size __n, const _Tp& __x)
{
- typedef typename iterator_traits<_ForwardIterator>::value_type _ValueType;
- typedef typename std::__is_scalar<_ValueType>::__type _Is_POD;
- std::__uninitialized_fill_n_aux(__first, __n, __x, _Is_POD());
+ typedef typename iterator_traits<_ForwardIterator>::value_type
+ _ValueType;
+ if (__is_pod(_ValueType))
+ std::fill_n(__first, __n, __x);
+ else
+ std::__uninitialized_fill_n_aux(__first, __n, __x);
}
// Extensions: versions of uninitialized_copy, uninitialized_fill,
Index: include/bits/stl_tempbuf.h
===================================================================
--- include/bits/stl_tempbuf.h (revision 123420)
+++ include/bits/stl_tempbuf.h (working copy)
@@ -90,13 +90,6 @@
size_type _M_len;
pointer _M_buffer;
- void
- _M_initialize_buffer(const _Tp&, __true_type) { }
-
- void
- _M_initialize_buffer(const _Tp& __val, __false_type)
- { std::uninitialized_fill_n(_M_buffer, _M_len, __val); }
-
public:
/// As per Table mumble.
size_type
@@ -145,17 +138,14 @@
: _M_original_len(std::distance(__first, __last)),
_M_len(0), _M_buffer(0)
{
- // Workaround for a __type_traits bug in the pre-7.3 compiler.
- typedef typename std::__is_scalar<_Tp>::__type _Trivial;
-
try
{
pair<pointer, size_type> __p(get_temporary_buffer<
value_type>(_M_original_len));
_M_buffer = __p.first;
_M_len = __p.second;
- if (_M_len > 0)
- _M_initialize_buffer(*__first, _Trivial());
+ if (!__is_pod(_Tp) && _M_len > 0)
+ std::uninitialized_fill_n(_M_buffer, _M_len, *__first);
}
catch(...)
{
Index: include/bits/stl_construct.h
===================================================================
--- include/bits/stl_construct.h (revision 123420)
+++ include/bits/stl_construct.h (working copy)
@@ -1,6 +1,7 @@
// nonstandard construct and destroy functions -*- C++ -*-
-// Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007
+// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
@@ -61,7 +62,6 @@
#ifndef _STL_CONSTRUCT_H
#define _STL_CONSTRUCT_H 1
-#include <bits/cpp_type_traits.h>
#include <new>
_GLIBCXX_BEGIN_NAMESPACE(std)
@@ -108,36 +108,6 @@
/**
* @if maint
- * Destroy a range of objects with nontrivial destructors.
- *
- * This is a helper function used only by _Destroy().
- * @endif
- */
- template<typename _ForwardIterator>
- inline void
- __destroy_aux(_ForwardIterator __first, _ForwardIterator __last,
- __false_type)
- {
- for (; __first != __last; ++__first)
- std::_Destroy(&*__first);
- }
-
- /**
- * @if maint
- * Destroy a range of objects with trivial destructors. Since the destructors
- * are trivial, there's nothing to do and hopefully this function will be
- * entirely optimized away.
- *
- * This is a helper function used only by _Destroy().
- * @endif
- */
- template<typename _ForwardIterator>
- inline void
- __destroy_aux(_ForwardIterator, _ForwardIterator, __true_type)
- { }
-
- /**
- * @if maint
* Destroy a range of objects. If the value_type of the object has
* a trivial destructor, the compiler should optimize all of this
* away, otherwise the objects' destructors must be invoked.
@@ -149,10 +119,9 @@
{
typedef typename iterator_traits<_ForwardIterator>::value_type
_Value_type;
- typedef typename std::__is_scalar<_Value_type>::__type
- _Has_trivial_destructor;
-
- std::__destroy_aux(__first, __last, _Has_trivial_destructor());
+ if (!__has_trivial_destructor(_Value_type))
+ for (; __first != __last; ++__first)
+ std::_Destroy(&*__first);
}
/**