Commit fe27aa8b by Paolo Carlini

stl_construct.h (_Construct): Change to variadic in C++0x mode, consistently…

stl_construct.h (_Construct): Change to variadic in C++0x mode, consistently with allocator::construct.

2010-06-16  Paolo Carlini  <paolo.carlini@oracle.com>

	* include/bits/stl_construct.h (_Construct): Change to variadic in
	C++0x mode, consistently with allocator::construct.
	* include/bits/stl_uninitialized.h (__uninitialized_copy_n): Use
	_Construct.
	(__uninitialized_construct_range): Move to...
	* include/bits/stl_tempbuf.h (__uninitialized_construct_buf): ... here.

From-SVN: r160833
parent 29be3835
2010-06-16 Paolo Carlini <paolo.carlini@oracle.com>
* include/bits/stl_construct.h (_Construct): Change to variadic in
C++0x mode, consistently with allocator::construct.
* include/bits/stl_uninitialized.h (__uninitialized_copy_n): Use
_Construct.
(__uninitialized_construct_range): Move to...
* include/bits/stl_tempbuf.h (__uninitialized_construct_buf): ... here.
2010-06-16 Matthias Klose <doko@ubuntu.com> 2010-06-16 Matthias Klose <doko@ubuntu.com>
* src/compatibility.cc: Export long double versions of "C" math * src/compatibility.cc: Export long double versions of "C" math
...@@ -11,23 +20,28 @@ ...@@ -11,23 +20,28 @@
* testsuite/lib/prune.exp (dg-prune-output): New. * testsuite/lib/prune.exp (dg-prune-output): New.
(libstdc++-dg-prune): Rename from prune_g++_output. (libstdc++-dg-prune): Rename from prune_g++_output.
Add a bunch of prunes from gcc's prune.exp. Add a bunch of prunes from gcc's prune.exp.
* testsuite/18_support/headers/cstdbool/std_c++0x_neg.cc: Remove dg-excess-errors. * testsuite/18_support/headers/cstdbool/std_c++0x_neg.cc:
Remove dg-excess-errors.
* testsuite/18_support/headers/cstdint/std_c++0x_neg.cc: Likewise. * testsuite/18_support/headers/cstdint/std_c++0x_neg.cc: Likewise.
* testsuite/19_diagnostics/error_category/cons/copy_neg.cc: Likewise. * testsuite/19_diagnostics/error_category/cons/copy_neg.cc: Likewise.
* testsuite/19_diagnostics/headers/system_error/std_c++0x_neg.cc: Likewise. * testsuite/19_diagnostics/headers/system_error/std_c++0x_neg.cc:
Likewise.
* testsuite/20_util/declval/requirements/1_neg.cc: Likewise. * testsuite/20_util/declval/requirements/1_neg.cc: Likewise.
* testsuite/20_util/duration/requirements/typedefs_neg1.cc: Likewise. * testsuite/20_util/duration/requirements/typedefs_neg1.cc: Likewise.
* testsuite/20_util/duration/requirements/typedefs_neg3.cc: Likewise. * testsuite/20_util/duration/requirements/typedefs_neg3.cc: Likewise.
* testsuite/20_util/headers/type_traits/std_c++0x_neg.cc: Likewise. * testsuite/20_util/headers/type_traits/std_c++0x_neg.cc: Likewise.
* testsuite/20_util/make_signed/requirements/typedefs_neg.cc: Likewise. * testsuite/20_util/make_signed/requirements/typedefs_neg.cc: Likewise.
* testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc: Likewise. * testsuite/20_util/make_unsigned/requirements/typedefs_neg.cc:
Likewise.
* testsuite/20_util/ratio/cons/cons_overflow_neg.cc: Likewise. * testsuite/20_util/ratio/cons/cons_overflow_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/assign/shared_ptr_neg.cc: Likewise. * testsuite/20_util/shared_ptr/assign/shared_ptr_neg.cc: Likewise.
* testsuite/20_util/shared_ptr/cons/43820.cc: Likewise. * testsuite/20_util/shared_ptr/cons/43820.cc: Likewise.
* testsuite/23_containers/headers/array/std_c++0x_neg.cc: Likewise. * testsuite/23_containers/headers/array/std_c++0x_neg.cc: Likewise.
* testsuite/23_containers/headers/tuple/std_c++0x_neg.cc: Likewise. * testsuite/23_containers/headers/tuple/std_c++0x_neg.cc: Likewise.
* testsuite/23_containers/headers/unordered_map/std_c++0x_neg.cc: Likewise. * testsuite/23_containers/headers/unordered_map/std_c++0x_neg.cc:
* testsuite/23_containers/headers/unordered_set/std_c++0x_neg.cc: Likewise. Likewise.
* testsuite/23_containers/headers/unordered_set/std_c++0x_neg.cc:
Likewise.
* testsuite/26_numerics/headers/ccomplex/std_c++0x_neg.cc: Likewise. * testsuite/26_numerics/headers/ccomplex/std_c++0x_neg.cc: Likewise.
* testsuite/26_numerics/headers/cfenv/std_c++0x_neg.cc: Likewise. * testsuite/26_numerics/headers/cfenv/std_c++0x_neg.cc: Likewise.
* testsuite/26_numerics/headers/ctgmath/std_c++0x_neg.cc: Likewise. * testsuite/26_numerics/headers/ctgmath/std_c++0x_neg.cc: Likewise.
...@@ -35,9 +49,12 @@ ...@@ -35,9 +49,12 @@
* testsuite/27_io/headers/cinttypes/std_c++0x_neg.cc: Likewise. * testsuite/27_io/headers/cinttypes/std_c++0x_neg.cc: Likewise.
* testsuite/28_regex/headers/regex/std_c++0x_neg.cc: Likewise. * testsuite/28_regex/headers/regex/std_c++0x_neg.cc: Likewise.
* testsuite/29_atomics/atomic/cons/copy_neg.cc: Likewise. * testsuite/29_atomics/atomic/cons/copy_neg.cc: Likewise.
* testsuite/29_atomics/atomic_integral/operators/decrement_neg.cc: Likewise. * testsuite/29_atomics/atomic_integral/operators/decrement_neg.cc:
* testsuite/29_atomics/atomic_integral/operators/increment_neg.cc: Likewise. Likewise.
* testsuite/30_threads/headers/condition_variable/std_c++0x_neg.cc: Likewise. * testsuite/29_atomics/atomic_integral/operators/increment_neg.cc:
Likewise.
* testsuite/30_threads/headers/condition_variable/std_c++0x_neg.cc:
Likewise.
* testsuite/30_threads/headers/future/std_c++0x_neg.cc: Likewise. * testsuite/30_threads/headers/future/std_c++0x_neg.cc: Likewise.
* testsuite/30_threads/headers/mutex/std_c++0x_neg.cc: Likewise. * testsuite/30_threads/headers/mutex/std_c++0x_neg.cc: Likewise.
* testsuite/30_threads/headers/thread/std_c++0x_neg.cc: Likewise. * testsuite/30_threads/headers/thread/std_c++0x_neg.cc: Likewise.
...@@ -45,7 +62,8 @@ ...@@ -45,7 +62,8 @@
* testsuite/ext/profile/mutex_extensions.cc: Likewise. * testsuite/ext/profile/mutex_extensions.cc: Likewise.
* testsuite/ext/type_traits/add_unsigned_floating_neg.cc: Likewise. * testsuite/ext/type_traits/add_unsigned_floating_neg.cc: Likewise.
* testsuite/ext/type_traits/remove_unsigned_floating_neg.cc: Likewise. * testsuite/ext/type_traits/remove_unsigned_floating_neg.cc: Likewise.
* testsuite/tr1/2_general_utilities/shared_ptr/assign/shared_ptr_neg.cc: Likewise. * testsuite/tr1/2_general_utilities/shared_ptr/assign/
shared_ptr_neg.cc: Likewise.
* testsuite/tr1/2_general_utilities/shared_ptr/cons/43820.cc: Likewise. * testsuite/tr1/2_general_utilities/shared_ptr/cons/43820.cc: Likewise.
2010-06-13 Paolo Carlini <paolo.carlini@oracle.com> 2010-06-13 Paolo Carlini <paolo.carlini@oracle.com>
......
...@@ -67,19 +67,21 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -67,19 +67,21 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
* Constructs an object in existing memory by invoking an allocated * Constructs an object in existing memory by invoking an allocated
* object's constructor with an initializer. * object's constructor with an initializer.
*/ */
template<typename _T1, typename _T2>
inline void
#ifdef __GXX_EXPERIMENTAL_CXX0X__ #ifdef __GXX_EXPERIMENTAL_CXX0X__
// Allow perfect forwarding template<typename _T1, typename... _Args>
_Construct(_T1* __p, _T2&& __value) inline void
_Construct(_T1* __p, _Args&&... __args)
{ ::new(static_cast<void*>(__p)) _T1(std::forward<_Args>(__args)...); }
#else #else
template<typename _T1, typename _T2>
inline void
_Construct(_T1* __p, const _T2& __value) _Construct(_T1* __p, const _T2& __value)
#endif
{ {
// _GLIBCXX_RESOLVE_LIB_DEFECTS // _GLIBCXX_RESOLVE_LIB_DEFECTS
// 402. wrong new expression in [some_]allocator::construct // 402. wrong new expression in [some_]allocator::construct
::new(static_cast<void*>(__p)) _T1(_GLIBCXX_FORWARD(_T2, __value)); ::new(static_cast<void*>(__p)) _T1(__value);
} }
#endif
/** /**
* Destroy the object pointed to by a pointer type. * Destroy the object pointed to by a pointer type.
......
...@@ -59,7 +59,6 @@ ...@@ -59,7 +59,6 @@
#include <bits/stl_algobase.h> #include <bits/stl_algobase.h>
#include <bits/stl_construct.h> #include <bits/stl_construct.h>
#include <bits/stl_uninitialized.h>
_GLIBCXX_BEGIN_NAMESPACE(std) _GLIBCXX_BEGIN_NAMESPACE(std)
...@@ -176,6 +175,70 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -176,6 +175,70 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
operator=(const _Temporary_buffer&); operator=(const _Temporary_buffer&);
}; };
template<bool>
struct __uninitialized_construct_buf_dispatch
{
template<typename _ForwardIterator, typename _Tp>
static void
__ucr(_ForwardIterator __first, _ForwardIterator __last,
_Tp& __value)
{
if(__first == __last)
return;
_ForwardIterator __cur = __first;
__try
{
std::_Construct(std::__addressof(*__first),
_GLIBCXX_MOVE(__value));
_ForwardIterator __prev = __cur;
++__cur;
for(; __cur != __last; ++__cur, ++__prev)
std::_Construct(std::__addressof(*__cur),
_GLIBCXX_MOVE(*__prev));
__value = _GLIBCXX_MOVE(*__prev);
}
__catch(...)
{
std::_Destroy(__first, __cur);
__throw_exception_again;
}
}
};
template<>
struct __uninitialized_construct_buf_dispatch<true>
{
template<typename _ForwardIterator, typename _Tp>
static void
__ucr(_ForwardIterator, _ForwardIterator, _Tp&) { }
};
// Constructs objects in the range [first, last).
// Note that while these new objects will take valid values,
// their exact value is not defined. In particular they may
// be 'moved from'.
//
// While __value may altered during this algorithm, it will have
// the same value when the algorithm finishes, unless one of the
// constructions throws.
//
// Requirements: _ForwardIterator::value_type(_Tp&&) is valid.
template<typename _ForwardIterator, typename _Tp>
inline void
__uninitialized_construct_buf(_ForwardIterator __first,
_ForwardIterator __last,
_Tp& __value)
{
typedef typename std::iterator_traits<_ForwardIterator>::value_type
_ValueType;
std::__uninitialized_construct_buf_dispatch<
__has_trivial_constructor(_ValueType)>::
__ucr(__first, __last, __value);
}
template<typename _ForwardIterator, typename _Tp> template<typename _ForwardIterator, typename _Tp>
_Temporary_buffer<_ForwardIterator, _Tp>:: _Temporary_buffer<_ForwardIterator, _Tp>::
_Temporary_buffer(_ForwardIterator __first, _ForwardIterator __last) _Temporary_buffer(_ForwardIterator __first, _ForwardIterator __last)
...@@ -189,8 +252,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -189,8 +252,8 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
_M_buffer = __p.first; _M_buffer = __p.first;
_M_len = __p.second; _M_len = __p.second;
if(_M_buffer) if(_M_buffer)
std::__uninitialized_construct_range(_M_buffer, _M_buffer + _M_len, std::__uninitialized_construct_buf(_M_buffer, _M_buffer + _M_len,
*__first); *__first);
} }
__catch(...) __catch(...)
{ {
......
...@@ -173,70 +173,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -173,70 +173,6 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
template<bool> template<bool>
struct __uninitialized_construct_range_dispatch
{
template<typename _ForwardIterator, typename _Tp>
static void
__ucr(_ForwardIterator __first, _ForwardIterator __last,
_Tp& __value)
{
if(__first == __last)
return;
_ForwardIterator __cur = __first;
__try
{
std::_Construct(std::__addressof(*__first),
_GLIBCXX_MOVE(__value));
_ForwardIterator __prev = __cur;
++__cur;
for(; __cur != __last; ++__cur, ++__prev)
std::_Construct(std::__addressof(*__cur),
_GLIBCXX_MOVE(*__prev));
__value = _GLIBCXX_MOVE(*__prev);
}
__catch(...)
{
std::_Destroy(__first, __cur);
__throw_exception_again;
}
}
};
template<>
struct __uninitialized_construct_range_dispatch<true>
{
template<typename _ForwardIterator, typename _Tp>
static void
__ucr(_ForwardIterator, _ForwardIterator, _Tp&) { }
};
// Constructs objects in the range [first, last).
// Note that while these new objects will take valid values,
// their exact value is not defined. In particular they may
// be 'moved from'.
//
// While __value may altered during this algorithm, it will have
// the same value when the algorithm finishes, unless one of the
// constructions throws.
//
// Requirements: _ForwardIterator::value_type(_Tp&&) is valid.
template<typename _ForwardIterator, typename _Tp>
inline void
__uninitialized_construct_range(_ForwardIterator __first,
_ForwardIterator __last,
_Tp& __value)
{
typedef typename std::iterator_traits<_ForwardIterator>::value_type
_ValueType;
std::__uninitialized_construct_range_dispatch<
__has_trivial_constructor(_ValueType)>::
__ucr(__first, __last, __value);
}
template<bool>
struct __uninitialized_fill_n struct __uninitialized_fill_n
{ {
template<typename _ForwardIterator, typename _Size, typename _Tp> template<typename _ForwardIterator, typename _Size, typename _Tp>
...@@ -501,8 +437,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std) ...@@ -501,8 +437,7 @@ _GLIBCXX_BEGIN_NAMESPACE(std)
__try __try
{ {
for (; __n > 0; --__n, ++__first, ++__cur) for (; __n > 0; --__n, ++__first, ++__cur)
::new(static_cast<void*>(std::__addressof(*__cur))) typename std::_Construct(std::__addressof(*__cur), *__first);
iterator_traits<_ForwardIterator>::value_type(*__first);
return __cur; return __cur;
} }
__catch(...) __catch(...)
......
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