diff options
Diffstat (limited to 'contrib/libc++/include/functional')
-rw-r--r-- | contrib/libc++/include/functional | 178 |
1 files changed, 136 insertions, 42 deletions
diff --git a/contrib/libc++/include/functional b/contrib/libc++/include/functional index dbe9b01..581f965 100644 --- a/contrib/libc++/include/functional +++ b/contrib/libc++/include/functional @@ -207,6 +207,8 @@ public: template <class Predicate> binary_negate<Predicate> not2(const Predicate& pred); +template <class F> unspecified not_fn(F&& f); // C++17 + template<class T> struct is_bind_expression; template<class T> struct is_placeholder; @@ -407,7 +409,7 @@ public: // function modifiers: void swap(function&) noexcept; template<class F, class Alloc> - void assign(F&&, const Alloc&); + void assign(F&&, const Alloc&); // Removed in C++17 // function capacity: explicit operator bool() const noexcept; @@ -1564,6 +1566,10 @@ class _LIBCPP_TYPE_VIS_ONLY function<_Rp(_ArgTypes...)> typename aligned_storage<3*sizeof(void*)>::type __buf_; __base* __f_; + _LIBCPP_NO_CFI static __base *__as_base(void *p) { + return reinterpret_cast<__base*>(p); + } + template <class _Fp, bool = !is_same<_Fp, function>::value && __invokable<_Fp&, _ArgTypes...>::value> struct __callable; @@ -1626,10 +1632,13 @@ public: // function modifiers: void swap(function&) _NOEXCEPT; + +#if _LIBCPP_STD_VER <= 14 template<class _Fp, class _Alloc> _LIBCPP_INLINE_VISIBILITY void assign(_Fp&& __f, const _Alloc& __a) {function(allocator_arg, __a, _VSTD::forward<_Fp>(__f)).swap(*this);} +#endif // function capacity: _LIBCPP_INLINE_VISIBILITY @@ -1657,9 +1666,9 @@ function<_Rp(_ArgTypes...)>::function(const function& __f) { if (__f.__f_ == 0) __f_ = 0; - else if (__f.__f_ == (const __base*)&__f.__buf_) + else if ((void *)__f.__f_ == &__f.__buf_) { - __f_ = (__base*)&__buf_; + __f_ = __as_base(&__buf_); __f.__f_->__clone(__f_); } else @@ -1673,9 +1682,9 @@ function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, { if (__f.__f_ == 0) __f_ = 0; - else if (__f.__f_ == (const __base*)&__f.__buf_) + else if ((void *)__f.__f_ == &__f.__buf_) { - __f_ = (__base*)&__buf_; + __f_ = __as_base(&__buf_); __f.__f_->__clone(__f_); } else @@ -1687,9 +1696,9 @@ function<_Rp(_ArgTypes...)>::function(function&& __f) _NOEXCEPT { if (__f.__f_ == 0) __f_ = 0; - else if (__f.__f_ == (__base*)&__f.__buf_) + else if ((void *)__f.__f_ == &__f.__buf_) { - __f_ = (__base*)&__buf_; + __f_ = __as_base(&__buf_); __f.__f_->__clone(__f_); } else @@ -1706,9 +1715,9 @@ function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc&, { if (__f.__f_ == 0) __f_ = 0; - else if (__f.__f_ == (__base*)&__f.__buf_) + else if ((void *)__f.__f_ == &__f.__buf_) { - __f_ = (__base*)&__buf_; + __f_ = __as_base(&__buf_); __f.__f_->__clone(__f_); } else @@ -1733,8 +1742,7 @@ function<_Rp(_ArgTypes...)>::function(_Fp __f, typedef __function::__func<_Fp, allocator<_Fp>, _Rp(_ArgTypes...)> _FF; if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value) { - __f_ = (__base*)&__buf_; - ::new (__f_) _FF(_VSTD::move(__f)); + __f_ = ::new((void*)&__buf_) _FF(_VSTD::move(__f)); } else { @@ -1763,8 +1771,7 @@ function<_Rp(_ArgTypes...)>::function(allocator_arg_t, const _Alloc& __a0, _Fp _ if (sizeof(_FF) <= sizeof(__buf_) && is_nothrow_copy_constructible<_Fp>::value && is_nothrow_copy_constructible<_Ap>::value) { - __f_ = (__base*)&__buf_; - ::new (__f_) _FF(_VSTD::move(__f), _Alloc(__a)); + __f_ = ::new((void*)&__buf_) _FF(_VSTD::move(__f), _Alloc(__a)); } else { @@ -1788,16 +1795,16 @@ template<class _Rp, class ..._ArgTypes> function<_Rp(_ArgTypes...)>& function<_Rp(_ArgTypes...)>::operator=(function&& __f) _NOEXCEPT { - if (__f_ == (__base*)&__buf_) + if ((void *)__f_ == &__buf_) __f_->destroy(); else if (__f_) __f_->destroy_deallocate(); __f_ = 0; if (__f.__f_ == 0) __f_ = 0; - else if (__f.__f_ == (__base*)&__f.__buf_) + else if ((void *)__f.__f_ == &__f.__buf_) { - __f_ = (__base*)&__buf_; + __f_ = __as_base(&__buf_); __f.__f_->__clone(__f_); } else @@ -1812,7 +1819,7 @@ template<class _Rp, class ..._ArgTypes> function<_Rp(_ArgTypes...)>& function<_Rp(_ArgTypes...)>::operator=(nullptr_t) _NOEXCEPT { - if (__f_ == (__base*)&__buf_) + if ((void *)__f_ == &__buf_) __f_->destroy(); else if (__f_) __f_->destroy_deallocate(); @@ -1837,7 +1844,7 @@ function<_Rp(_ArgTypes...)>::operator=(_Fp&& __f) template<class _Rp, class ..._ArgTypes> function<_Rp(_ArgTypes...)>::~function() { - if (__f_ == (__base*)&__buf_) + if ((void *)__f_ == &__buf_) __f_->destroy(); else if (__f_) __f_->destroy_deallocate(); @@ -1847,34 +1854,34 @@ template<class _Rp, class ..._ArgTypes> void function<_Rp(_ArgTypes...)>::swap(function& __f) _NOEXCEPT { - if (__f_ == (__base*)&__buf_ && __f.__f_ == (__base*)&__f.__buf_) + if ((void *)__f_ == &__buf_ && (void *)__f.__f_ == &__f.__buf_) { typename aligned_storage<sizeof(__buf_)>::type __tempbuf; - __base* __t = (__base*)&__tempbuf; + __base* __t = __as_base(&__tempbuf); __f_->__clone(__t); __f_->destroy(); __f_ = 0; - __f.__f_->__clone((__base*)&__buf_); + __f.__f_->__clone(__as_base(&__buf_)); __f.__f_->destroy(); __f.__f_ = 0; - __f_ = (__base*)&__buf_; - __t->__clone((__base*)&__f.__buf_); + __f_ = __as_base(&__buf_); + __t->__clone(__as_base(&__f.__buf_)); __t->destroy(); - __f.__f_ = (__base*)&__f.__buf_; + __f.__f_ = __as_base(&__f.__buf_); } - else if (__f_ == (__base*)&__buf_) + else if ((void *)__f_ == &__buf_) { - __f_->__clone((__base*)&__f.__buf_); + __f_->__clone(__as_base(&__f.__buf_)); __f_->destroy(); __f_ = __f.__f_; - __f.__f_ = (__base*)&__f.__buf_; + __f.__f_ = __as_base(&__f.__buf_); } - else if (__f.__f_ == (__base*)&__f.__buf_) + else if ((void *)__f.__f_ == &__f.__buf_) { - __f.__f_->__clone((__base*)&__buf_); + __f.__f_->__clone(__as_base(&__buf_)); __f.__f_->destroy(); __f.__f_ = __f_; - __f_ = (__base*)&__buf_; + __f_ = __as_base(&__buf_); } else _VSTD::swap(__f_, __f.__f_); @@ -1973,16 +1980,29 @@ namespace placeholders template <int _Np> struct __ph {}; -_LIBCPP_FUNC_VIS extern __ph<1> _1; -_LIBCPP_FUNC_VIS extern __ph<2> _2; -_LIBCPP_FUNC_VIS extern __ph<3> _3; -_LIBCPP_FUNC_VIS extern __ph<4> _4; -_LIBCPP_FUNC_VIS extern __ph<5> _5; -_LIBCPP_FUNC_VIS extern __ph<6> _6; -_LIBCPP_FUNC_VIS extern __ph<7> _7; -_LIBCPP_FUNC_VIS extern __ph<8> _8; -_LIBCPP_FUNC_VIS extern __ph<9> _9; -_LIBCPP_FUNC_VIS extern __ph<10> _10; +#if defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_BIND) +_LIBCPP_FUNC_VIS extern const __ph<1> _1; +_LIBCPP_FUNC_VIS extern const __ph<2> _2; +_LIBCPP_FUNC_VIS extern const __ph<3> _3; +_LIBCPP_FUNC_VIS extern const __ph<4> _4; +_LIBCPP_FUNC_VIS extern const __ph<5> _5; +_LIBCPP_FUNC_VIS extern const __ph<6> _6; +_LIBCPP_FUNC_VIS extern const __ph<7> _7; +_LIBCPP_FUNC_VIS extern const __ph<8> _8; +_LIBCPP_FUNC_VIS extern const __ph<9> _9; +_LIBCPP_FUNC_VIS extern const __ph<10> _10; +#else +constexpr __ph<1> _1{}; +constexpr __ph<2> _2{}; +constexpr __ph<3> _3{}; +constexpr __ph<4> _4{}; +constexpr __ph<5> _5{}; +constexpr __ph<6> _6{}; +constexpr __ph<7> _7{}; +constexpr __ph<8> _8{}; +constexpr __ph<9> _9{}; +constexpr __ph<10> _10{}; +#endif // defined(_LIBCPP_CXX03_LANG) || defined(_LIBCPP_BUILDING_BIND) } // placeholders @@ -2468,6 +2488,22 @@ struct _LIBCPP_TYPE_VIS_ONLY hash<unsigned long long> { }; +#ifndef _LIBCPP_HAS_NO_INT128 + +template <> +struct _LIBCPP_TYPE_VIS_ONLY hash<__int128_t> + : public __scalar_hash<__int128_t> +{ +}; + +template <> +struct _LIBCPP_TYPE_VIS_ONLY hash<__uint128_t> + : public __scalar_hash<__uint128_t> +{ +}; + +#endif + template <> struct _LIBCPP_TYPE_VIS_ONLY hash<float> : public __scalar_hash<float> @@ -2564,11 +2600,69 @@ struct _LIBCPP_TYPE_VIS_ONLY hash #if _LIBCPP_STD_VER > 14 + template <class _Fn, class ..._Args> result_of_t<_Fn&&(_Args&&...)> -invoke(_Fn&& __f, _Args&&... __args) { - return __invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...); +invoke(_Fn&& __f, _Args&&... __args) + noexcept(noexcept(_VSTD::__invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...))) +{ + return _VSTD::__invoke(_VSTD::forward<_Fn>(__f), _VSTD::forward<_Args>(__args)...); +} + +template <class _DecayFunc> +class _LIBCPP_TYPE_VIS_ONLY __not_fn_imp { + _DecayFunc __fd; + +public: + __not_fn_imp() = delete; + + template <class ..._Args> + _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)...); } + + 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)...); } + + 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)...); } + + + 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)...); } + +private: + template <class _RawFunc, + class = enable_if_t<!is_same<decay_t<_RawFunc>, __not_fn_imp>::value>> + _LIBCPP_INLINE_VISIBILITY + explicit __not_fn_imp(_RawFunc&& __rf) + : __fd(_VSTD::forward<_RawFunc>(__rf)) {} + + template <class _RawFunc> + friend inline _LIBCPP_INLINE_VISIBILITY + __not_fn_imp<decay_t<_RawFunc>> not_fn(_RawFunc&&); +}; + +template <class _RawFunc> +inline _LIBCPP_INLINE_VISIBILITY +__not_fn_imp<decay_t<_RawFunc>> not_fn(_RawFunc&& __fn) { + return __not_fn_imp<decay_t<_RawFunc>>(_VSTD::forward<_RawFunc>(__fn)); } + #endif // struct hash<T*> in <memory> |