From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1059) id C53DC3892446; Mon, 29 Jun 2020 21:09:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C53DC3892446 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1593464978; bh=09LQ+IE/pFbHwpx23/2GXxeBALt+w6RXGG12sfN/tQs=; h=From:To:Subject:Date:From; b=Yw1L5DgFbxzhihnPKD8HnIfhtYpF89YjntqT79QuLIv4OxS96ojnSTEXByw2gOGeR FtfLzGlMwltVslFXJPScrzbg2pPT/JikN6uuelFlbVuv+K1DcXXj4rdHR4ffUhYx6Z 5COVf3aihs5gAqxdDShG4VJEMUcGxv6Vc6nyk0i4= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Nathan Sidwell To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc/devel/c++-modules] libstdc++: Define all std::function members inline X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/devel/c++-modules X-Git-Oldrev: 465520e3eb45d83ad18394aa537150bfa6bdf117 X-Git-Newrev: abed8b56b92b103275e6871b689862c0495b761b Message-Id: <20200629210938.C53DC3892446@sourceware.org> Date: Mon, 29 Jun 2020 21:09:38 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 29 Jun 2020 21:09:38 -0000 https://gcc.gnu.org/g:abed8b56b92b103275e6871b689862c0495b761b commit abed8b56b92b103275e6871b689862c0495b761b Author: Jonathan Wakely Date: Fri Jun 19 14:37:52 2020 +0100 libstdc++: Define all std::function members inline * include/bits/std_function.h (function): Define all member functions inline. Diff: --- libstdc++-v3/include/bits/std_function.h | 159 +++++++++++++------------------ 1 file changed, 65 insertions(+), 94 deletions(-) diff --git a/libstdc++-v3/include/bits/std_function.h b/libstdc++-v3/include/bits/std_function.h index e2bf9b91850..fa65885d1de 100644 --- a/libstdc++-v3/include/bits/std_function.h +++ b/libstdc++-v3/include/bits/std_function.h @@ -345,7 +345,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * The newly-created %function contains a copy of the target of @a * __x (if it has one). */ - function(const function& __x); + function(const function& __x) + : _Function_base() + { + if (static_cast(__x)) + { + __x._M_manager(_M_functor, __x._M_functor, __clone_functor); + _M_invoker = __x._M_invoker; + _M_manager = __x._M_manager; + } + } /** * @brief %Function move constructor. @@ -354,10 +363,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * The newly-created %function contains the target of @a __x * (if it has one). */ - function(function&& __x) noexcept : _Function_base() - { - __x.swap(*this); - } + function(function&& __x) noexcept + : _Function_base() + { __x.swap(*this); } /** * @brief Builds a %function that targets a copy of the incoming @@ -378,7 +386,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION template>, void>, typename = _Requires<_Callable<_Functor>, void>> - function(_Functor); + function(_Functor __f) + : _Function_base() + { + typedef _Function_handler<_Res(_ArgTypes...), _Functor> _My_handler; + + if (_My_handler::_M_not_empty_function(__f)) + { + _My_handler::_M_init_functor(_M_functor, std::move(__f)); + _M_invoker = &_My_handler::_M_invoke; + _M_manager = &_My_handler::_M_manager; + } + } /** * @brief %Function assignment operator. @@ -508,7 +527,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * The function call operator invokes the target function object * stored by @c this. */ - _Res operator()(_ArgTypes... __args) const; + _Res + operator()(_ArgTypes... __args) const + { + if (_M_empty()) + __throw_bad_function_call(); + return _M_invoker(_M_functor, std::forward<_ArgTypes>(__args)...); + } #if __cpp_rtti // [3.7.2.5] function target access @@ -521,7 +546,18 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * * This function will not throw an %exception. */ - const type_info& target_type() const noexcept; + const type_info& + target_type() const noexcept + { + if (_M_manager) + { + _Any_data __typeinfo_result; + _M_manager(__typeinfo_result, _M_functor, __get_type_info); + return *__typeinfo_result._M_access(); + } + else + return typeid(void); + } /** * @brief Access the stored target function object. @@ -534,9 +570,28 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION * * @{ */ - template _Functor* target() noexcept; + template + _Functor* + target() noexcept + { + const function* __const_this = this; + const _Functor* __func = __const_this->template target<_Functor>(); + return const_cast<_Functor*>(__func); + } - template const _Functor* target() const noexcept; + template + const _Functor* + target() const noexcept + { + if (typeid(_Functor) == target_type() && _M_manager) + { + _Any_data __ptr; + _M_manager(__ptr, _M_functor, __get_functor_ptr); + return __ptr._M_access(); + } + else + return nullptr; + } // @} #endif @@ -582,90 +637,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION function(_Functor) -> function<_Signature>; #endif - // Out-of-line member definitions. - template - function<_Res(_ArgTypes...)>:: - function(const function& __x) - : _Function_base() - { - if (static_cast(__x)) - { - __x._M_manager(_M_functor, __x._M_functor, __clone_functor); - _M_invoker = __x._M_invoker; - _M_manager = __x._M_manager; - } - } - - template - template - function<_Res(_ArgTypes...)>:: - function(_Functor __f) - : _Function_base() - { - typedef _Function_handler<_Res(_ArgTypes...), _Functor> _My_handler; - - if (_My_handler::_M_not_empty_function(__f)) - { - _My_handler::_M_init_functor(_M_functor, std::move(__f)); - _M_invoker = &_My_handler::_M_invoke; - _M_manager = &_My_handler::_M_manager; - } - } - - template - _Res - function<_Res(_ArgTypes...)>:: - operator()(_ArgTypes... __args) const - { - if (_M_empty()) - __throw_bad_function_call(); - return _M_invoker(_M_functor, std::forward<_ArgTypes>(__args)...); - } - -#if __cpp_rtti - template - const type_info& - function<_Res(_ArgTypes...)>:: - target_type() const noexcept - { - if (_M_manager) - { - _Any_data __typeinfo_result; - _M_manager(__typeinfo_result, _M_functor, __get_type_info); - return *__typeinfo_result._M_access(); - } - else - return typeid(void); - } - - template - template - _Functor* - function<_Res(_ArgTypes...)>:: - target() noexcept - { - const function* __const_this = this; - const _Functor* __func = __const_this->template target<_Functor>(); - return const_cast<_Functor*>(__func); - } - - template - template - const _Functor* - function<_Res(_ArgTypes...)>:: - target() const noexcept - { - if (typeid(_Functor) == target_type() && _M_manager) - { - _Any_data __ptr; - _M_manager(__ptr, _M_functor, __get_functor_ptr); - return __ptr._M_access(); - } - else - return nullptr; - } -#endif - // [20.7.15.2.6] null pointer comparisons /**