From 603d2c098945d33117fbe9c87c996d57bff31dc1 Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Sat, 28 May 2011 17:59:48 +0000 Subject: [PATCH] noexcept for . git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@132264 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/__functional_base | 14 ++-- include/functional | 170 ++++++++++++++++++-------------------- 2 files changed, 89 insertions(+), 95 deletions(-) diff --git a/include/__functional_base b/include/__functional_base index caf0093e..f2aa5041 100644 --- a/include/__functional_base +++ b/include/__functional_base @@ -350,14 +350,14 @@ private: public: // construct/copy/destroy - _LIBCPP_INLINE_VISIBILITY reference_wrapper(type& __f) : __f_(&__f) {} + _LIBCPP_INLINE_VISIBILITY reference_wrapper(type& __f) _NOEXCEPT : __f_(&__f) {} #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES private: reference_wrapper(type&&); public: // = delete; // do not bind to temps #endif // access - _LIBCPP_INLINE_VISIBILITY operator type& () const {return *__f_;} - _LIBCPP_INLINE_VISIBILITY type& get() const {return *__f_;} + _LIBCPP_INLINE_VISIBILITY operator type& () const _NOEXCEPT {return *__f_;} + _LIBCPP_INLINE_VISIBILITY type& get() const _NOEXCEPT {return *__f_;} // invoke template @@ -377,7 +377,7 @@ template struct __is_reference_wrapper template inline _LIBCPP_INLINE_VISIBILITY reference_wrapper<_Tp> -ref(_Tp& __t) +ref(_Tp& __t) _NOEXCEPT { return reference_wrapper<_Tp>(__t); } @@ -385,7 +385,7 @@ ref(_Tp& __t) template inline _LIBCPP_INLINE_VISIBILITY reference_wrapper<_Tp> -ref(reference_wrapper<_Tp> __t) +ref(reference_wrapper<_Tp> __t) _NOEXCEPT { return ref(__t.get()); } @@ -393,7 +393,7 @@ ref(reference_wrapper<_Tp> __t) template inline _LIBCPP_INLINE_VISIBILITY reference_wrapper -cref(const _Tp& __t) +cref(const _Tp& __t) _NOEXCEPT { return reference_wrapper(__t); } @@ -401,7 +401,7 @@ cref(const _Tp& __t) template inline _LIBCPP_INLINE_VISIBILITY reference_wrapper -cref(reference_wrapper<_Tp> __t) +cref(reference_wrapper<_Tp> __t) _NOEXCEPT { return cref(__t.get()); } diff --git a/include/functional b/include/functional index 03e2c816..82a4a923 100644 --- a/include/functional +++ b/include/functional @@ -43,16 +43,16 @@ public: typedef see below result_type; // Not always defined // construct/copy/destroy - reference_wrapper(T&); + reference_wrapper(T&) noexcept; reference_wrapper(T&&) = delete; // do not bind to temps - reference_wrapper(const reference_wrapper& x); + reference_wrapper(const reference_wrapper& x) noexcept; // assignment - reference_wrapper& operator=(const reference_wrapper& x); + reference_wrapper& operator=(const reference_wrapper& x) noexcept; // access - operator T& () const; - T& get() const; + operator T& () const noexcept; + T& get() const noexcept; // invoke template @@ -60,13 +60,13 @@ public: operator() (ArgTypes&&...) const; }; -template reference_wrapper ref(T& t); +template reference_wrapper ref(T& t) noexcept; template void ref(const T&& t) = delete; -template reference_wrapper ref(reference_wrappert); +template reference_wrapper ref(reference_wrappert) noexcept; -template reference_wrapper cref(const T& t); +template reference_wrapper cref(const T& t) noexcept; template void cref(const T&& t) = delete; -template reference_wrapper cref(reference_wrapper t); +template reference_wrapper cref(reference_wrapper t) noexcept; template struct plus : binary_function @@ -365,16 +365,16 @@ public: typedef R result_type; // construct/copy/destroy: - function(); - function(nullptr_t); + function() noexcept; + function(nullptr_t) noexcept; function(const function&); - function(function&&); + function(function&&) noexcept; template function(F); template - function(allocator_arg_t, const Alloc&); + function(allocator_arg_t, const Alloc&) noexcept; template - function(allocator_arg_t, const Alloc&, nullptr_t); + function(allocator_arg_t, const Alloc&, nullptr_t) noexcept; template function(allocator_arg_t, const Alloc&, const function&); template @@ -383,54 +383,48 @@ public: function(allocator_arg_t, const Alloc&, F); function& operator=(const function&); - function& operator=(function&&); + function& operator=(function&&) noexcept; function& operator=(nullptr_t); template function& operator=(F&&); template - function& operator=(reference_wrapper); + function& operator=(reference_wrapper) noexcept; ~function(); // function modifiers: - void swap(function&); + void swap(function&) noexcept; template void assign(F&&, const Alloc&); // function capacity: - explicit operator bool() const; - - // deleted overloads close possible hole in the type system - template - bool operator==(const function&) = delete; - template - bool operator!=(const function&) = delete; + explicit operator bool() const noexcept; // function invocation: R operator()(ArgTypes...) const; // function target access: - const std::type_info& target_type() const; - template T* target(); - template const T* target() const; + const std::type_info& target_type() const noexcept; + template T* target() noexcept; + template const T* target() const noexcept; }; // Null pointer comparisons: template - bool operator==(const function&, nullptr_t); + bool operator==(const function&, nullptr_t) noexcept; template - bool operator==(nullptr_t, const function&); + bool operator==(nullptr_t, const function&) noexcept; template - bool operator!=(const function&, nullptr_t); + bool operator!=(const function&, nullptr_t) noexcept; template - bool operator!=(nullptr_t, const function&); + bool operator!=(nullptr_t, const function&) noexcept; // specialized algorithms: template - void swap(function&, function&); + void swap(function&, function&) noexcept; template struct hash; @@ -980,12 +974,12 @@ public: _LIBCPP_INLINE_VISIBILITY virtual ~__base() {} virtual __base* __clone() const = 0; virtual void __clone(__base*) const = 0; - virtual void destroy() = 0; - virtual void destroy_deallocate() = 0; + virtual void destroy() _NOEXCEPT = 0; + virtual void destroy_deallocate() _NOEXCEPT = 0; virtual _R operator()(_ArgTypes&& ...) = 0; #ifndef _LIBCPP_NO_RTTI - virtual const void* target(const type_info&) const = 0; - virtual const std::type_info& target_type() const = 0; + virtual const void* target(const type_info&) const _NOEXCEPT = 0; + virtual const std::type_info& target_type() const _NOEXCEPT = 0; #endif // _LIBCPP_NO_RTTI }; @@ -1003,12 +997,12 @@ public: explicit __func(_F __f, _Alloc __a) : __f_(_STD::move(__f), _STD::move(__a)) {} virtual __base<_R(_ArgTypes...)>* __clone() const; virtual void __clone(__base<_R(_ArgTypes...)>*) const; - virtual void destroy(); - virtual void destroy_deallocate(); + virtual void destroy() _NOEXCEPT; + virtual void destroy_deallocate() _NOEXCEPT; virtual _R operator()(_ArgTypes&& ... __arg); #ifndef _LIBCPP_NO_RTTI - virtual const void* target(const type_info&) const; - virtual const std::type_info& target_type() const; + virtual const void* target(const type_info&) const _NOEXCEPT; + virtual const std::type_info& target_type() const _NOEXCEPT; #endif // _LIBCPP_NO_RTTI }; @@ -1033,14 +1027,14 @@ __func<_F, _Alloc, _R(_ArgTypes...)>::__clone(__base<_R(_ArgTypes...)>* __p) con template void -__func<_F, _Alloc, _R(_ArgTypes...)>::destroy() +__func<_F, _Alloc, _R(_ArgTypes...)>::destroy() _NOEXCEPT { __f_.~__compressed_pair<_F, _Alloc>(); } template void -__func<_F, _Alloc, _R(_ArgTypes...)>::destroy_deallocate() +__func<_F, _Alloc, _R(_ArgTypes...)>::destroy_deallocate() _NOEXCEPT { typedef typename _Alloc::template rebind<__func>::other _A; _A __a(__f_.second()); @@ -1059,7 +1053,7 @@ __func<_F, _Alloc, _R(_ArgTypes...)>::operator()(_ArgTypes&& ... __arg) template const void* -__func<_F, _Alloc, _R(_ArgTypes...)>::target(const type_info& __ti) const +__func<_F, _Alloc, _R(_ArgTypes...)>::target(const type_info& __ti) const _NOEXCEPT { if (__ti == typeid(_F)) return &__f_.first(); @@ -1068,7 +1062,7 @@ __func<_F, _Alloc, _R(_ArgTypes...)>::target(const type_info& __ti) const template const std::type_info& -__func<_F, _Alloc, _R(_ArgTypes...)>::target_type() const +__func<_F, _Alloc, _R(_ArgTypes...)>::target_type() const _NOEXCEPT { return typeid(_F); } @@ -1112,21 +1106,21 @@ public: // construct/copy/destroy: _LIBCPP_INLINE_VISIBILITY - function() : __f_(0) {} + function() _NOEXCEPT : __f_(0) {} _LIBCPP_INLINE_VISIBILITY - function(nullptr_t) : __f_(0) {} + function(nullptr_t) _NOEXCEPT : __f_(0) {} function(const function&); - function(function&&); + function(function&&) _NOEXCEPT; template function(_F, typename enable_if::value>::type* = 0); template _LIBCPP_INLINE_VISIBILITY - function(allocator_arg_t, const _Alloc&) : __f_(0) {} + function(allocator_arg_t, const _Alloc&) _NOEXCEPT : __f_(0) {} template _LIBCPP_INLINE_VISIBILITY - function(allocator_arg_t, const _Alloc&, nullptr_t) : __f_(0) {} + function(allocator_arg_t, const _Alloc&, nullptr_t) _NOEXCEPT : __f_(0) {} template function(allocator_arg_t, const _Alloc&, const function&); template @@ -1136,8 +1130,8 @@ public: typename enable_if::value>::type* = 0); function& operator=(const function&); - function& operator=(function&&); - function& operator=(nullptr_t); + function& operator=(function&&) _NOEXCEPT; + function& operator=(nullptr_t) _NOEXCEPT; template typename enable_if < @@ -1149,7 +1143,7 @@ public: ~function(); // function modifiers: - void swap(function&); + void swap(function&) _NOEXCEPT; template _LIBCPP_INLINE_VISIBILITY void assign(_F&& __f, const _Alloc& __a) @@ -1157,7 +1151,7 @@ public: // function capacity: _LIBCPP_INLINE_VISIBILITY - /*explicit*/ operator bool() const {return __f_;} + /*explicit*/ operator bool() const _NOEXCEPT {return __f_;} // deleted overloads close possible hole in the type system template @@ -1170,9 +1164,9 @@ public: #ifndef _LIBCPP_NO_RTTI // function target access: - const std::type_info& target_type() const; - template _T* target(); - template const _T* target() const; + const std::type_info& target_type() const _NOEXCEPT; + template _T* target() _NOEXCEPT; + template const _T* target() const _NOEXCEPT; #endif // _LIBCPP_NO_RTTI }; @@ -1207,7 +1201,7 @@ function<_R(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, } template -function<_R(_ArgTypes...)>::function(function&& __f) +function<_R(_ArgTypes...)>::function(function&& __f) _NOEXCEPT { if (__f.__f_ == 0) __f_ = 0; @@ -1251,7 +1245,7 @@ function<_R(_ArgTypes...)>::function(_F __f, if (__not_null(__f)) { typedef __function::__func<_F, allocator<_F>, _R(_ArgTypes...)> _FF; - if (sizeof(_FF) <= sizeof(__buf_)) + if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_F>::value) { __f_ = (__base*)&__buf_; ::new (__f_) _FF(_STD::move(__f)); @@ -1278,7 +1272,7 @@ function<_R(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _F __f if (__not_null(__f)) { typedef __function::__func<_F, _Alloc, _R(_ArgTypes...)> _FF; - if (sizeof(_FF) <= sizeof(__buf_)) + if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_F>::value) { __f_ = (__base*)&__buf_; ::new (__f_) _FF(_STD::move(__f)); @@ -1311,7 +1305,7 @@ function<_R(_ArgTypes...)>::operator=(const function& __f) template function<_R(_ArgTypes...)>& -function<_R(_ArgTypes...)>::operator=(function&& __f) +function<_R(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT { if (__f_ == (__base*)&__buf_) __f_->destroy(); @@ -1334,7 +1328,7 @@ function<_R(_ArgTypes...)>::operator=(function&& __f) template function<_R(_ArgTypes...)>& -function<_R(_ArgTypes...)>::operator=(nullptr_t) +function<_R(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT { if (__f_ == (__base*)&__buf_) __f_->destroy(); @@ -1367,7 +1361,7 @@ function<_R(_ArgTypes...)>::~function() template void -function<_R(_ArgTypes...)>::swap(function& __f) +function<_R(_ArgTypes...)>::swap(function& __f) _NOEXCEPT { if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) { @@ -1417,7 +1411,7 @@ function<_R(_ArgTypes...)>::operator()(_ArgTypes... __arg) const template const std::type_info& -function<_R(_ArgTypes...)>::target_type() const +function<_R(_ArgTypes...)>::target_type() const _NOEXCEPT { if (__f_ == 0) return typeid(void); @@ -1427,7 +1421,7 @@ function<_R(_ArgTypes...)>::target_type() const template template _T* -function<_R(_ArgTypes...)>::target() +function<_R(_ArgTypes...)>::target() _NOEXCEPT { if (__f_ == 0) return (_T*)0; @@ -1437,7 +1431,7 @@ function<_R(_ArgTypes...)>::target() template template const _T* -function<_R(_ArgTypes...)>::target() const +function<_R(_ArgTypes...)>::target() const _NOEXCEPT { if (__f_ == 0) return (const _T*)0; @@ -1449,27 +1443,27 @@ function<_R(_ArgTypes...)>::target() const template inline _LIBCPP_INLINE_VISIBILITY bool -operator==(const function<_R(_ArgTypes...)>& __f, nullptr_t) {return !__f;} +operator==(const function<_R(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return !__f;} template inline _LIBCPP_INLINE_VISIBILITY bool -operator==(nullptr_t, const function<_R(_ArgTypes...)>& __f) {return !__f;} +operator==(nullptr_t, const function<_R(_ArgTypes...)>& __f) _NOEXCEPT {return !__f;} template inline _LIBCPP_INLINE_VISIBILITY bool -operator!=(const function<_R(_ArgTypes...)>& __f, nullptr_t) {return (bool)__f;} +operator!=(const function<_R(_ArgTypes...)>& __f, nullptr_t) _NOEXCEPT {return (bool)__f;} template inline _LIBCPP_INLINE_VISIBILITY bool -operator!=(nullptr_t, const function<_R(_ArgTypes...)>& __f) {return (bool)__f;} +operator!=(nullptr_t, const function<_R(_ArgTypes...)>& __f) _NOEXCEPT {return (bool)__f;} template inline _LIBCPP_INLINE_VISIBILITY void -swap(function<_R(_ArgTypes...)>& __x, function<_R(_ArgTypes...)>& __y) +swap(function<_R(_ArgTypes...)>& __x, function<_R(_ArgTypes...)>& __y) _NOEXCEPT {return __x.swap(__y);} template struct __is_bind_expression : public false_type {}; @@ -1753,7 +1747,7 @@ struct _LIBCPP_VISIBLE hash : public unary_function { _LIBCPP_INLINE_VISIBILITY - size_t operator()(bool __v) const {return static_cast(__v);} + size_t operator()(bool __v) const _NOEXCEPT {return static_cast(__v);} }; template <> @@ -1761,7 +1755,7 @@ struct _LIBCPP_VISIBLE hash : public unary_function { _LIBCPP_INLINE_VISIBILITY - size_t operator()(char __v) const {return static_cast(__v);} + size_t operator()(char __v) const _NOEXCEPT {return static_cast(__v);} }; template <> @@ -1769,7 +1763,7 @@ struct _LIBCPP_VISIBLE hash : public unary_function { _LIBCPP_INLINE_VISIBILITY - size_t operator()(signed char __v) const {return static_cast(__v);} + size_t operator()(signed char __v) const _NOEXCEPT {return static_cast(__v);} }; template <> @@ -1777,7 +1771,7 @@ struct _LIBCPP_VISIBLE hash : public unary_function { _LIBCPP_INLINE_VISIBILITY - size_t operator()(unsigned char __v) const {return static_cast(__v);} + size_t operator()(unsigned char __v) const _NOEXCEPT {return static_cast(__v);} }; #ifndef _LIBCPP_HAS_NO_UNICODE_CHARS @@ -1787,7 +1781,7 @@ struct _LIBCPP_VISIBLE hash : public unary_function { _LIBCPP_INLINE_VISIBILITY - size_t operator()(char16_t __v) const {return static_cast(__v);} + size_t operator()(char16_t __v) const _NOEXCEPT {return static_cast(__v);} }; template <> @@ -1795,7 +1789,7 @@ struct _LIBCPP_VISIBLE hash : public unary_function { _LIBCPP_INLINE_VISIBILITY - size_t operator()(char32_t __v) const {return static_cast(__v);} + size_t operator()(char32_t __v) const _NOEXCEPT {return static_cast(__v);} }; #endif // _LIBCPP_HAS_NO_UNICODE_CHARS @@ -1805,7 +1799,7 @@ struct _LIBCPP_VISIBLE hash : public unary_function { _LIBCPP_INLINE_VISIBILITY - size_t operator()(wchar_t __v) const {return static_cast(__v);} + size_t operator()(wchar_t __v) const _NOEXCEPT {return static_cast(__v);} }; template <> @@ -1813,7 +1807,7 @@ struct _LIBCPP_VISIBLE hash : public unary_function { _LIBCPP_INLINE_VISIBILITY - size_t operator()(short __v) const {return static_cast(__v);} + size_t operator()(short __v) const _NOEXCEPT {return static_cast(__v);} }; template <> @@ -1821,7 +1815,7 @@ struct _LIBCPP_VISIBLE hash : public unary_function { _LIBCPP_INLINE_VISIBILITY - size_t operator()(unsigned short __v) const {return static_cast(__v);} + size_t operator()(unsigned short __v) const _NOEXCEPT {return static_cast(__v);} }; template <> @@ -1829,7 +1823,7 @@ struct _LIBCPP_VISIBLE hash : public unary_function { _LIBCPP_INLINE_VISIBILITY - size_t operator()(int __v) const {return static_cast(__v);} + size_t operator()(int __v) const _NOEXCEPT {return static_cast(__v);} }; template <> @@ -1837,7 +1831,7 @@ struct _LIBCPP_VISIBLE hash : public unary_function { _LIBCPP_INLINE_VISIBILITY - size_t operator()(unsigned int __v) const {return static_cast(__v);} + size_t operator()(unsigned int __v) const _NOEXCEPT {return static_cast(__v);} }; template <> @@ -1845,7 +1839,7 @@ struct _LIBCPP_VISIBLE hash : public unary_function { _LIBCPP_INLINE_VISIBILITY - size_t operator()(long __v) const {return static_cast(__v);} + size_t operator()(long __v) const _NOEXCEPT {return static_cast(__v);} }; template <> @@ -1853,7 +1847,7 @@ struct _LIBCPP_VISIBLE hash : public unary_function { _LIBCPP_INLINE_VISIBILITY - size_t operator()(unsigned long __v) const {return static_cast(__v);} + size_t operator()(unsigned long __v) const _NOEXCEPT {return static_cast(__v);} }; template <> @@ -1861,7 +1855,7 @@ struct _LIBCPP_VISIBLE hash : public unary_function { _LIBCPP_INLINE_VISIBILITY - size_t operator()(long long __v) const + size_t operator()(long long __v) const _NOEXCEPT { size_t __r = 0; const size_t* const __p = reinterpret_cast(&__v); @@ -1876,7 +1870,7 @@ struct _LIBCPP_VISIBLE hash : public unary_function { _LIBCPP_INLINE_VISIBILITY - size_t operator()(unsigned long long __v) const + size_t operator()(unsigned long long __v) const _NOEXCEPT { size_t __r = 0; const size_t* const __p = reinterpret_cast(&__v); @@ -1891,7 +1885,7 @@ struct _LIBCPP_VISIBLE hash : public unary_function { _LIBCPP_INLINE_VISIBILITY - size_t operator()(float __v) const + size_t operator()(float __v) const _NOEXCEPT { if (__v == 0) return 0; @@ -1905,7 +1899,7 @@ struct _LIBCPP_VISIBLE hash : public unary_function { _LIBCPP_INLINE_VISIBILITY - size_t operator()(double __v) const + size_t operator()(double __v) const _NOEXCEPT { if (__v == 0) return 0; @@ -1922,7 +1916,7 @@ struct _LIBCPP_VISIBLE hash : public unary_function { _LIBCPP_INLINE_VISIBILITY - size_t operator()(long double __v) const + size_t operator()(long double __v) const _NOEXCEPT { if (__v == 0) return 0;