diff options
Diffstat (limited to 'libstdc++-v3/include')
-rw-r--r-- | libstdc++-v3/include/bits/deque.tcc | 4 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/stl_list.h | 4 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/stl_tree.h | 8 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/stl_vector.h | 4 | ||||
-rw-r--r-- | libstdc++-v3/include/ext/debug_allocator.h | 105 | ||||
-rw-r--r-- | libstdc++-v3/include/std/chrono | 2 | ||||
-rw-r--r-- | libstdc++-v3/include/std/future | 197 | ||||
-rw-r--r-- | libstdc++-v3/include/std/mutex | 9 | ||||
-rw-r--r-- | libstdc++-v3/include/std/type_traits | 2 |
9 files changed, 230 insertions, 105 deletions
diff --git a/libstdc++-v3/include/bits/deque.tcc b/libstdc++-v3/include/bits/deque.tcc index 369e0eda531..89c5ef76ba6 100644 --- a/libstdc++-v3/include/bits/deque.tcc +++ b/libstdc++-v3/include/bits/deque.tcc @@ -381,7 +381,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER __try { for (; __first != __last; ++__first) +#if __cplusplus >= 201103L + emplace_back(*__first); +#else push_back(*__first); +#endif } __catch(...) { diff --git a/libstdc++-v3/include/bits/stl_list.h b/libstdc++-v3/include/bits/stl_list.h index cc6edb3da7f..596760c2152 100644 --- a/libstdc++-v3/include/bits/stl_list.h +++ b/libstdc++-v3/include/bits/stl_list.h @@ -1487,7 +1487,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER __false_type) { for (; __first != __last; ++__first) +#if __cplusplus >= 201103L + emplace_back(*__first); +#else push_back(*__first); +#endif } // Called by list(n,v,a), and the range constructor when it turns out diff --git a/libstdc++-v3/include/bits/stl_tree.h b/libstdc++-v3/include/bits/stl_tree.h index 59883fca834..cb5a8eff800 100644 --- a/libstdc++-v3/include/bits/stl_tree.h +++ b/libstdc++-v3/include/bits/stl_tree.h @@ -62,6 +62,9 @@ #include <bits/allocator.h> #include <bits/stl_function.h> #include <bits/cpp_type_traits.h> +#if __cplusplus >= 201103L +#include <bits/alloc_traits.h> +#endif namespace std _GLIBCXX_VISIBILITY(default) { @@ -400,8 +403,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _Link_type __tmp = _M_get_node(); __try { - _M_get_Node_allocator().construct(__tmp, - std::forward<_Args>(__args)...); + allocator_traits<_Node_allocator>:: + construct(_M_get_Node_allocator(), __tmp, + std::forward<_Args>(__args)...); } __catch(...) { diff --git a/libstdc++-v3/include/bits/stl_vector.h b/libstdc++-v3/include/bits/stl_vector.h index d880ba77905..69c6e278c06 100644 --- a/libstdc++-v3/include/bits/stl_vector.h +++ b/libstdc++-v3/include/bits/stl_vector.h @@ -1184,7 +1184,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER _InputIterator __last, std::input_iterator_tag) { for (; __first != __last; ++__first) +#if __cplusplus >= 201103L + emplace_back(*__first); +#else push_back(*__first); +#endif } // Called by the second initialize_dispatch above diff --git a/libstdc++-v3/include/ext/debug_allocator.h b/libstdc++-v3/include/ext/debug_allocator.h index 8190d2a89a7..9bb73f06161 100644 --- a/libstdc++-v3/include/ext/debug_allocator.h +++ b/libstdc++-v3/include/ext/debug_allocator.h @@ -43,6 +43,8 @@ #define _DEBUG_ALLOCATOR_H 1 #include <stdexcept> +#include <bits/functexcept.h> +#include <ext/alloc_traits.h> namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) { @@ -51,24 +53,35 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION using std::size_t; /** - * @brief A meta-allocator with debugging bits, as per [20.4]. + * @brief A meta-allocator with debugging bits. * @ingroup allocators * - * This is precisely the allocator defined in the C++ Standard. - * - all allocation calls operator new - * - all deallocation calls operator delete + * This is precisely the allocator defined in the C++03 Standard. */ template<typename _Alloc> class debug_allocator { + template<typename> friend class debug_allocator; + + typedef __alloc_traits<_Alloc> _Traits; + public: - typedef typename _Alloc::size_type size_type; - typedef typename _Alloc::difference_type difference_type; - typedef typename _Alloc::pointer pointer; - typedef typename _Alloc::const_pointer const_pointer; - typedef typename _Alloc::reference reference; - typedef typename _Alloc::const_reference const_reference; - typedef typename _Alloc::value_type value_type; + typedef typename _Traits::size_type size_type; + typedef typename _Traits::difference_type difference_type; + typedef typename _Traits::pointer pointer; + typedef typename _Traits::const_pointer const_pointer; + typedef typename _Traits::reference reference; + typedef typename _Traits::const_reference const_reference; + typedef typename _Traits::value_type value_type; + + template<typename _Up> + class rebind + { + typedef typename _Traits::template rebind<_Up>::other __other; + + public: + typedef debug_allocator<__other> other; + }; private: // _M_extra is the number of objects that correspond to the @@ -77,13 +90,34 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION _Alloc _M_allocator; - public: - debug_allocator() + template<typename _Alloc2, + typename = typename _Alloc2::template rebind<value_type>::other> + struct __convertible + { }; + + template<typename _Alloc2> + struct __convertible<_Alloc2, _Alloc> + { + typedef void* __type; + }; + + size_type _S_extra() { const size_t __obj_size = sizeof(value_type); - _M_extra = (sizeof(size_type) + __obj_size - 1) / __obj_size; + return (sizeof(size_type) + __obj_size - 1) / __obj_size; } - + + public: + debug_allocator() : _M_extra(_S_extra()) { } + + template<typename _Alloc2> + debug_allocator(const debug_allocator<_Alloc2>& __a2, + typename __convertible<_Alloc2>::__type = 0) + : _M_allocator(__a2._M_allocator), _M_extra(_S_extra()) { } + + debug_allocator(const _Alloc& __a) + : _M_allocator(__a), _M_extra(_S_extra()) { } + pointer allocate(size_type __n) { @@ -105,21 +139,52 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION void deallocate(pointer __p, size_type __n) { + using std::__throw_runtime_error; if (__p) { pointer __real_p = __p - _M_extra; if (*reinterpret_cast<size_type*>(__real_p) != __n) - { - throw std::runtime_error("debug_allocator::deallocate" - " wrong size"); - } + __throw_runtime_error("debug_allocator::deallocate wrong size"); _M_allocator.deallocate(__real_p, __n + _M_extra); } else - throw std::runtime_error("debug_allocator::deallocate null pointer"); + __throw_runtime_error("debug_allocator::deallocate null pointer"); } + + void + construct(pointer __p, const value_type& __val) + { _Traits::construct(_M_allocator, __p, __val); } + +#if __cplusplus >= 201103L + template<typename _Tp, typename... _Args> + void + construct(_Tp* __p, _Args&&... __args) + { + _Traits::construct(_M_allocator, __p, + std::forward<_Args>(__args)...); + } +#endif + + template<typename _Tp> + void + destroy(_Tp* __p) + { _Traits::destroy(_M_allocator, __p); } + + size_type + max_size() const throw() + { return _Traits::max_size(_M_allocator) - _M_extra; } + + friend bool + operator==(const debug_allocator& __lhs, const debug_allocator& __rhs) + { return __lhs._M_allocator == __rhs._M_allocator; } }; + template<typename _Alloc> + inline bool + operator!=(const debug_allocator<_Alloc>& __lhs, + const debug_allocator<_Alloc>& __rhs) + { return !(__lhs == __rhs); } + _GLIBCXX_END_NAMESPACE_VERSION } // namespace diff --git a/libstdc++-v3/include/std/chrono b/libstdc++-v3/include/std/chrono index e4b92a59405..711131920f0 100644 --- a/libstdc++-v3/include/std/chrono +++ b/libstdc++-v3/include/std/chrono @@ -225,7 +225,7 @@ _GLIBCXX_END_NAMESPACE_VERSION { return numeric_limits<_Rep>::lowest(); } }; - template<typename T> + template<typename _Tp> struct __is_ratio : std::false_type { }; diff --git a/libstdc++-v3/include/std/future b/libstdc++-v3/include/std/future index 6cccd3d3f2a..30100fe05e4 100644 --- a/libstdc++-v3/include/std/future +++ b/libstdc++-v3/include/std/future @@ -214,6 +214,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION bool _M_initialized; public: + typedef _Res result_type; + _Result() noexcept : _M_initialized() { } ~_Result() @@ -281,17 +283,23 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION typename __traits::allocator_type __a2(__a); __result_type* __p = __traits::allocate(__a2, 1); __try - { - __traits::construct(__a2, __p, __a); - } + { + __traits::construct(__a2, __p, __a); + } __catch(...) - { - __traits::deallocate(__a2, __p, 1); - __throw_exception_again; - } + { + __traits::deallocate(__a2, __p, 1); + __throw_exception_again; + } return _Ptr<__result_type>(__p); } + template<typename _Res, typename _Tp> + static _Ptr<_Result<_Res>> + _S_allocate_result(const std::allocator<_Tp>& __a) + { + return _Ptr<_Result<_Res>>(new _Result<_Res>); + } /// Base class for state between a promise and one or more /// associated futures. @@ -482,6 +490,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION class _Async_state_impl; template<typename _Signature> + class _Task_state_base; + + template<typename _Fn, typename _Alloc, typename _Signature> class _Task_state; template<typename _BoundFn> @@ -492,24 +503,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION static std::shared_ptr<_State_base> _S_make_async_state(_BoundFn&& __fn); - template<typename _Res_ptr, typename _Res> + template<typename _Res_ptr, + typename _Res = typename _Res_ptr::element_type::result_type> struct _Task_setter; template<typename _Res_ptr, typename _BoundFn> - class _Task_setter_helper - { - typedef typename remove_reference<_BoundFn>::type::result_type __res; - public: - typedef _Task_setter<_Res_ptr, __res> __type; - }; - - template<typename _Res_ptr, typename _BoundFn> - static typename _Task_setter_helper<_Res_ptr, _BoundFn>::__type + static _Task_setter<_Res_ptr> _S_task_setter(_Res_ptr& __ptr, _BoundFn&& __call) { - typedef _Task_setter_helper<_Res_ptr, _BoundFn> __helper_type; - typedef typename __helper_type::__type _Setter; - return _Setter{ __ptr, std::ref(__call) }; + return _Task_setter<_Res_ptr>{ __ptr, std::ref(__call) }; } }; @@ -517,6 +519,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<typename _Res> struct __future_base::_Result<_Res&> : __future_base::_Result_base { + typedef _Res& result_type; + _Result() noexcept : _M_value_ptr() { } void _M_set(_Res& __res) noexcept { _M_value_ptr = &__res; } @@ -533,6 +537,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<> struct __future_base::_Result<void> : __future_base::_Result_base { + typedef void result_type; + private: void _M_destroy() { delete this; } }; @@ -1197,7 +1203,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { _Ptr_type operator()() { - __try + __try { _M_result->_M_set(_M_fn()); } @@ -1205,7 +1211,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { _M_result->_M_error = current_exception(); } - return std::move(_M_result); + return std::move(_M_result); } _Ptr_type& _M_result; std::function<_Res()> _M_fn; @@ -1216,7 +1222,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION { _Ptr_type operator()() { - __try + __try { _M_fn(); } @@ -1231,49 +1237,85 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION }; template<typename _Res, typename... _Args> - struct __future_base::_Task_state<_Res(_Args...)> final + struct __future_base::_Task_state_base<_Res(_Args...)> : __future_base::_State_base { typedef _Res _Res_type; - _Task_state(std::function<_Res(_Args...)> __task) - : _M_result(new _Result<_Res>()), _M_task(std::move(__task)) - { } + template<typename _Alloc> + _Task_state_base(const _Alloc& __a) + : _M_result(_S_allocate_result<_Res>(__a)) + { } - template<typename _Func, typename _Alloc> - _Task_state(_Func&& __task, const _Alloc& __a) - : _M_result(_S_allocate_result<_Res>(__a)), - _M_task(allocator_arg, __a, std::move(__task)) - { } + virtual void + _M_run(_Args... __args) = 0; - void + virtual shared_ptr<_Task_state_base> + _M_reset() = 0; + + typedef __future_base::_Ptr<_Result<_Res>> _Ptr_type; + _Ptr_type _M_result; + }; + + template<typename _Fn, typename _Alloc, typename _Res, typename... _Args> + struct __future_base::_Task_state<_Fn, _Alloc, _Res(_Args...)> final + : __future_base::_Task_state_base<_Res(_Args...)> + { + _Task_state(_Fn&& __fn, const _Alloc& __a) + : _Task_state_base<_Res(_Args...)>(__a), _M_impl(std::move(__fn), __a) + { } + + private: + virtual void _M_run(_Args... __args) { - // bound arguments decay so wrap lvalue references - auto __boundfn = std::__bind_simple(std::ref(_M_task), + // bound arguments decay so wrap lvalue references + auto __boundfn = std::__bind_simple(std::ref(_M_impl._M_fn), _S_maybe_wrap_ref(std::forward<_Args>(__args))...); - auto __setter = _S_task_setter(_M_result, std::move(__boundfn)); - _M_set_result(std::move(__setter)); + auto __setter = _S_task_setter(this->_M_result, std::move(__boundfn)); + this->_M_set_result(std::move(__setter)); } - typedef __future_base::_Ptr<_Result<_Res>> _Ptr_type; - _Ptr_type _M_result; - std::function<_Res(_Args...)> _M_task; + virtual shared_ptr<_Task_state_base<_Res(_Args...)>> + _M_reset(); template<typename _Tp> - static reference_wrapper<_Tp> - _S_maybe_wrap_ref(_Tp& __t) - { return std::ref(__t); } + static reference_wrapper<_Tp> + _S_maybe_wrap_ref(_Tp& __t) + { return std::ref(__t); } template<typename _Tp> - static typename enable_if<!is_lvalue_reference<_Tp>::value, - _Tp>::type&& - _S_maybe_wrap_ref(_Tp&& __t) - { return std::forward<_Tp>(__t); } + static + typename enable_if<!is_lvalue_reference<_Tp>::value, _Tp>::type&& + _S_maybe_wrap_ref(_Tp&& __t) + { return std::forward<_Tp>(__t); } + + struct _Impl : _Alloc + { + _Impl(_Fn&& __fn, const _Alloc& __a) + : _Alloc(__a), _M_fn(std::move(__fn)) { } + _Fn _M_fn; + } _M_impl; }; + template<typename _Signature, typename _Fn, typename _Alloc> + static shared_ptr<__future_base::_Task_state_base<_Signature>> + __create_task_state(_Fn&& __fn, const _Alloc& __a) + { + typedef __future_base::_Task_state<_Fn, _Alloc, _Signature> _State; + return std::allocate_shared<_State>(__a, std::move(__fn), __a); + } + + template<typename _Fn, typename _Alloc, typename _Res, typename... _Args> + shared_ptr<__future_base::_Task_state_base<_Res(_Args...)>> + __future_base::_Task_state<_Fn, _Alloc, _Res(_Args...)>::_M_reset() + { + return __create_task_state<_Res(_Args...)>(std::move(_M_impl._M_fn), + static_cast<_Alloc&>(_M_impl)); + } + template<typename _Task, typename _Fn, bool - = is_same<_Task, typename decay<_Fn>::type>::value> + = is_same<_Task, typename decay<_Fn>::type>::value> struct __constrain_pkgdtask { typedef void __type; }; @@ -1285,7 +1327,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template<typename _Res, typename... _ArgTypes> class packaged_task<_Res(_ArgTypes...)> { - typedef __future_base::_Task_state<_Res(_ArgTypes...)> _State_type; + typedef __future_base::_Task_state_base<_Res(_ArgTypes...)> _State_type; shared_ptr<_State_type> _M_state; public: @@ -1295,31 +1337,30 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION // _GLIBCXX_RESOLVE_LIB_DEFECTS // 2095. missing constructors needed for uses-allocator construction template<typename _Allocator> - explicit - packaged_task(allocator_arg_t, const _Allocator& __a) noexcept - { } + packaged_task(allocator_arg_t, const _Allocator& __a) noexcept + { } template<typename _Fn, typename = typename - __constrain_pkgdtask<packaged_task, _Fn>::__type> - explicit - packaged_task(_Fn&& __fn) - : _M_state(std::make_shared<_State_type>(std::forward<_Fn>(__fn))) - { } + __constrain_pkgdtask<packaged_task, _Fn>::__type> + explicit + packaged_task(_Fn&& __fn) + : packaged_task(allocator_arg, std::allocator<int>(), std::move(__fn)) + { } // _GLIBCXX_RESOLVE_LIB_DEFECTS // 2097. packaged_task constructors should be constrained - template<typename _Fn, typename _Allocator, typename = typename - __constrain_pkgdtask<packaged_task, _Fn>::__type> - explicit - packaged_task(allocator_arg_t, const _Allocator& __a, _Fn&& __fn) - : _M_state(std::allocate_shared<_State_type>(__a, - std::forward<_Fn>(__fn))) - { } + template<typename _Fn, typename _Alloc, typename = typename + __constrain_pkgdtask<packaged_task, _Fn>::__type> + explicit + packaged_task(allocator_arg_t, const _Alloc& __a, _Fn&& __fn) + : _M_state(__create_task_state<_Res(_ArgTypes...)>( + std::forward<_Fn>(__fn), __a)) + { } ~packaged_task() { if (static_cast<bool>(_M_state) && !_M_state.unique()) - _M_state->_M_break_promise(std::move(_M_state->_M_result)); + _M_state->_M_break_promise(std::move(_M_state->_M_result)); } // No copy @@ -1327,24 +1368,22 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION packaged_task& operator=(const packaged_task&) = delete; template<typename _Allocator> - explicit - packaged_task(allocator_arg_t, const _Allocator&, - const packaged_task&) = delete; + packaged_task(allocator_arg_t, const _Allocator&, + const packaged_task&) = delete; // Move support packaged_task(packaged_task&& __other) noexcept { this->swap(__other); } template<typename _Allocator> - explicit - packaged_task(allocator_arg_t, const _Allocator&, - packaged_task&& __other) noexcept - { this->swap(__other); } + packaged_task(allocator_arg_t, const _Allocator&, + packaged_task&& __other) noexcept + { this->swap(__other); } packaged_task& operator=(packaged_task&& __other) noexcept { - packaged_task(std::move(__other)).swap(*this); - return *this; + packaged_task(std::move(__other)).swap(*this); + return *this; } void @@ -1364,15 +1403,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION void operator()(_ArgTypes... __args) { - __future_base::_State_base::_S_check(_M_state); - _M_state->_M_run(std::forward<_ArgTypes>(__args)...); + __future_base::_State_base::_S_check(_M_state); + _M_state->_M_run(std::forward<_ArgTypes>(__args)...); } void reset() { - __future_base::_State_base::_S_check(_M_state); - packaged_task(std::move(_M_state->_M_task)).swap(*this); + __future_base::_State_base::_S_check(_M_state); + packaged_task __tmp; + __tmp._M_state = _M_state; + _M_state = _M_state->_M_reset(); } }; diff --git a/libstdc++-v3/include/std/mutex b/libstdc++-v3/include/std/mutex index e327f28c1dd..67f34185deb 100644 --- a/libstdc++-v3/include/std/mutex +++ b/libstdc++-v3/include/std/mutex @@ -45,12 +45,13 @@ #include <bits/gthr.h> #include <bits/move.h> // for std::swap -#if defined(_GLIBCXX_HAS_GTHREADS) && defined(_GLIBCXX_USE_C99_STDINT_TR1) +#ifdef _GLIBCXX_USE_C99_STDINT_TR1 namespace std _GLIBCXX_VISIBILITY(default) { _GLIBCXX_BEGIN_NAMESPACE_VERSION +#ifdef _GLIBCXX_HAS_GTHREADS // Common base class for std::mutex and std::timed_mutex class __mutex_base { @@ -384,6 +385,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } }; #endif +#endif // _GLIBCXX_HAS_GTHREADS /// Do not acquire ownership of the mutex. struct defer_lock_t { }; @@ -719,6 +721,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION } } +#ifdef _GLIBCXX_HAS_GTHREADS /// once_flag struct once_flag { @@ -790,12 +793,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION if (__e) __throw_system_error(__e); } +#endif // _GLIBCXX_HAS_GTHREADS // @} group mutexes _GLIBCXX_END_NAMESPACE_VERSION } // namespace - -#endif // _GLIBCXX_HAS_GTHREADS && _GLIBCXX_USE_C99_STDINT_TR1 +#endif // _GLIBCXX_USE_C99_STDINT_TR1 #endif // C++11 diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits index 62d59128f9f..334b8d0ab38 100644 --- a/libstdc++-v3/include/std/type_traits +++ b/libstdc++-v3/include/std/type_traits @@ -444,7 +444,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION /// is_fundamental template<typename _Tp> struct is_fundamental - : public __or_<is_arithmetic<_Tp>, is_void<_Tp>>::type + : public __or_<is_arithmetic<_Tp>, is_void<_Tp>, __is_nullptr_t<_Tp>>::type { }; /// is_object |