diff options
Diffstat (limited to 'include/functional')
| -rw-r--r-- | include/functional | 171 |
1 files changed, 77 insertions, 94 deletions
diff --git a/include/functional b/include/functional index 581f965b2b81..eb8609f1469b 100644 --- a/include/functional +++ b/include/functional @@ -212,6 +212,13 @@ template <class F> unspecified not_fn(F&& f); // C++17 template<class T> struct is_bind_expression; template<class T> struct is_placeholder; + // See C++14 20.9.9, Function object binders +template <class T> constexpr bool is_bind_expression_v + = is_bind_expression<T>::value; // C++17 +template <class T> constexpr int is_placeholder_v + = is_placeholder<T>::value; // C++17 + + template<class Fn, class... BoundArgs> unspecified bind(Fn&&, BoundArgs&&...); template<class R, class Fn, class... BoundArgs> @@ -386,15 +393,15 @@ public: template<class F> function(F); template<Allocator Alloc> - function(allocator_arg_t, const Alloc&) noexcept; + function(allocator_arg_t, const Alloc&) noexcept; // removed in C++17 template<Allocator Alloc> - function(allocator_arg_t, const Alloc&, nullptr_t) noexcept; + function(allocator_arg_t, const Alloc&, nullptr_t) noexcept; // removed in C++17 template<Allocator Alloc> - function(allocator_arg_t, const Alloc&, const function&); + function(allocator_arg_t, const Alloc&, const function&); // removed in C++17 template<Allocator Alloc> - function(allocator_arg_t, const Alloc&, function&&); + function(allocator_arg_t, const Alloc&, function&&); // removed in C++17 template<class F, Allocator Alloc> - function(allocator_arg_t, const Alloc&, F); + function(allocator_arg_t, const Alloc&, F); // removed in C++17 function& operator=(const function&); function& operator=(function&&) noexcept; @@ -1382,6 +1389,16 @@ class _LIBCPP_EXCEPTION_ABI bad_function_call { }; +_LIBCPP_NORETURN inline _LIBCPP_ALWAYS_INLINE +void __throw_bad_function_call() +{ +#ifndef _LIBCPP_NO_EXCEPTIONS + throw bad_function_call(); +#else + _VSTD::abort(); +#endif +} + template<class _Fp> class _LIBCPP_TYPE_VIS_ONLY function; // undefined namespace __function @@ -1595,13 +1612,12 @@ public: function(nullptr_t) _NOEXCEPT : __f_(0) {} function(const function&); function(function&&) _NOEXCEPT; - template<class _Fp> - function(_Fp, typename enable_if - < - __callable<_Fp>::value && - !is_same<_Fp, function>::value - >::type* = 0); + template<class _Fp, class = typename enable_if< + __callable<_Fp>::value && !is_same<_Fp, function>::value + >::type> + function(_Fp); +#if _LIBCPP_STD_VER <= 14 template<class _Alloc> _LIBCPP_INLINE_VISIBILITY function(allocator_arg_t, const _Alloc&) _NOEXCEPT : __f_(0) {} @@ -1612,9 +1628,9 @@ public: function(allocator_arg_t, const _Alloc&, const function&); template<class _Alloc> function(allocator_arg_t, const _Alloc&, function&&); - template<class _Fp, class _Alloc> - function(allocator_arg_t, const _Alloc& __a, _Fp __f, - typename enable_if<__callable<_Fp>::value>::type* = 0); + template<class _Fp, class _Alloc, class = typename enable_if<__callable<_Fp>::value>::type> + function(allocator_arg_t, const _Alloc& __a, _Fp __f); +#endif function& operator=(const function&); function& operator=(function&&) _NOEXCEPT; @@ -1675,6 +1691,7 @@ function<_Rp(_ArgTypes...)>::function(const function& __f) __f_ = __f.__f_->__clone(); } +#if _LIBCPP_STD_VER <= 14 template<class _Rp, class ..._ArgTypes> template <class _Alloc> function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, @@ -1690,6 +1707,7 @@ function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, else __f_ = __f.__f_->__clone(); } +#endif template<class _Rp, class ..._ArgTypes> function<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT @@ -1708,6 +1726,7 @@ function<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT } } +#if _LIBCPP_STD_VER <= 14 template<class _Rp, class ..._ArgTypes> template <class _Alloc> function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, @@ -1726,15 +1745,11 @@ function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, __f.__f_ = 0; } } +#endif template<class _Rp, class ..._ArgTypes> -template <class _Fp> -function<_Rp(_ArgTypes...)>::function(_Fp __f, - typename enable_if - < - __callable<_Fp>::value && - !is_same<_Fp, function>::value - >::type*) +template <class _Fp, class> +function<_Rp(_ArgTypes...)>::function(_Fp __f) : __f_(0) { if (__function::__not_null(__f)) @@ -1756,10 +1771,10 @@ function<_Rp(_ArgTypes...)>::function(_Fp __f, } } +#if _LIBCPP_STD_VER <= 14 template<class _Rp, class ..._ArgTypes> -template <class _Fp, class _Alloc> -function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f, - typename enable_if<__callable<_Fp>::value>::type*) +template <class _Fp, class _Alloc, class> +function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _Fp __f) : __f_(0) { typedef allocator_traits<_Alloc> __alloc_traits; @@ -1782,6 +1797,7 @@ function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _Fp _ } } } +#endif template<class _Rp, class ..._ArgTypes> function<_Rp(_ArgTypes...)>& @@ -1854,6 +1870,8 @@ template<class _Rp, class ..._ArgTypes> void function<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT { + if (_VSTD::addressof(__f) == this) + return; if ((void *)__f_ == &__buf_ && (void *)__f.__f_ == &__f.__buf_) { typename aligned_storage<sizeof(__buf_)>::type __tempbuf; @@ -1891,10 +1909,8 @@ template<class _Rp, class ..._ArgTypes> _Rp function<_Rp(_ArgTypes...)>::operator()(_ArgTypes... __arg) const { -#ifndef _LIBCPP_NO_EXCEPTIONS if (__f_ == 0) - throw bad_function_call(); -#endif // _LIBCPP_NO_EXCEPTIONS + __throw_bad_function_call(); return (*__f_)(_VSTD::forward<_ArgTypes>(__arg)...); } @@ -1971,10 +1987,20 @@ template<class _Tp> struct __is_bind_expression : public false_type {}; template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_bind_expression : public __is_bind_expression<typename remove_cv<_Tp>::type> {}; +#if _LIBCPP_STD_VER > 14 +template <class _Tp> +constexpr size_t is_bind_expression_v = is_bind_expression<_Tp>::value; +#endif + template<class _Tp> struct __is_placeholder : public integral_constant<int, 0> {}; template<class _Tp> struct _LIBCPP_TYPE_VIS_ONLY is_placeholder : public __is_placeholder<typename remove_cv<_Tp>::type> {}; +#if _LIBCPP_STD_VER > 14 +template <class _Tp> +constexpr size_t is_placeholder_v = is_placeholder<_Tp>::value; +#endif + namespace placeholders { @@ -2204,36 +2230,6 @@ private: typedef typename __make_tuple_indices<sizeof...(_BoundArgs)>::type __indices; public: -#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS - - _LIBCPP_INLINE_VISIBILITY - __bind(const __bind& __b) - : __f_(__b.__f_), - __bound_args_(__b.__bound_args_) {} - - _LIBCPP_INLINE_VISIBILITY - __bind& operator=(const __bind& __b) - { - __f_ = __b.__f_; - __bound_args_ = __b.__bound_args_; - return *this; - } - - _LIBCPP_INLINE_VISIBILITY - __bind(__bind&& __b) - : __f_(_VSTD::move(__b.__f_)), - __bound_args_(_VSTD::move(__b.__bound_args_)) {} - - _LIBCPP_INLINE_VISIBILITY - __bind& operator=(__bind&& __b) - { - __f_ = _VSTD::move(__b.__f_); - __bound_args_ = _VSTD::move(__b.__bound_args_); - return *this; - } - -#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS - template <class _Gp, class ..._BA, class = typename enable_if < @@ -2278,31 +2274,6 @@ class __bind_r public: typedef _Rp result_type; -#ifdef _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS - - _LIBCPP_INLINE_VISIBILITY - __bind_r(const __bind_r& __b) - : base(_VSTD::forward<const base&>(__b)) {} - - _LIBCPP_INLINE_VISIBILITY - __bind_r& operator=(const __bind_r& __b) - { - base::operator=(_VSTD::forward<const base&>(__b)); - return *this; - } - - _LIBCPP_INLINE_VISIBILITY - __bind_r(__bind_r&& __b) - : base(_VSTD::forward<base>(__b)) {} - - _LIBCPP_INLINE_VISIBILITY - __bind_r& operator=(__bind_r&& __b) - { - base::operator=(_VSTD::forward<base>(__b)); - return *this; - } - -#endif // _LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS template <class _Gp, class ..._BA, class = typename enable_if @@ -2583,12 +2554,11 @@ struct _LIBCPP_TYPE_VIS_ONLY hash<long double> }; #if _LIBCPP_STD_VER > 11 -template <class _Tp> -struct _LIBCPP_TYPE_VIS_ONLY hash + +template <class _Tp, bool = is_enum<_Tp>::value> +struct _LIBCPP_TYPE_VIS_ONLY __enum_hash : public unary_function<_Tp, size_t> { - static_assert(is_enum<_Tp>::value, "This hash only works for enumeration types"); - _LIBCPP_INLINE_VISIBILITY size_t operator()(_Tp __v) const _NOEXCEPT { @@ -2596,11 +2566,24 @@ struct _LIBCPP_TYPE_VIS_ONLY hash return hash<type>{}(static_cast<type>(__v)); } }; +template <class _Tp> +struct _LIBCPP_TYPE_VIS_ONLY __enum_hash<_Tp, false> { + __enum_hash() = delete; + __enum_hash(__enum_hash const&) = delete; + __enum_hash& operator=(__enum_hash const&) = delete; +}; + +template <class _Tp> +struct _LIBCPP_TYPE_VIS_ONLY hash : public __enum_hash<_Tp> +{ +}; #endif #if _LIBCPP_STD_VER > 14 +#define __cpp_lib_invoke 201411 + template <class _Fn, class ..._Args> result_of_t<_Fn&&(_Args&&...)> invoke(_Fn&& __f, _Args&&... __args) @@ -2620,30 +2603,30 @@ public: _LIBCPP_INLINE_VISIBILITY auto operator()(_Args&& ...__args) & noexcept(noexcept(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...))) - -> decltype(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)) - { return !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); } + -> decltype( !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)) + { return !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); } template <class ..._Args> _LIBCPP_INLINE_VISIBILITY auto operator()(_Args&& ...__args) && noexcept(noexcept(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...))) - -> decltype(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...)) - { return !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...); } + -> decltype( !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...)) + { return !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...); } template <class ..._Args> _LIBCPP_INLINE_VISIBILITY auto operator()(_Args&& ...__args) const& noexcept(noexcept(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...))) - -> decltype(!_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)) - { return !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); } + -> decltype( !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...)) + { return !_VSTD::invoke(__fd, _VSTD::forward<_Args>(__args)...); } template <class ..._Args> _LIBCPP_INLINE_VISIBILITY auto operator()(_Args&& ...__args) const&& noexcept(noexcept(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...))) - -> decltype(!_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...)) - { return !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...); } + -> decltype( !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...)) + { return !_VSTD::invoke(_VSTD::move(__fd), _VSTD::forward<_Args>(__args)...); } private: template <class _RawFunc, |
