summaryrefslogtreecommitdiff
path: root/libstdc++-v3
diff options
context:
space:
mode:
authorredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>2014-10-29 18:38:31 +0000
committerredi <redi@138bc75d-0d04-0410-961f-82ee72b054a4>2014-10-29 18:38:31 +0000
commit1ceb3fa7741ad071994a33267270f8d705766d84 (patch)
tree70692bd39fb1147ca91c39c52dea645106e83937 /libstdc++-v3
parenta5118bd7288ed49f405424a184c784f86dd940b6 (diff)
downloadgcc-1ceb3fa7741ad071994a33267270f8d705766d84.tar.gz
Use perfect forwarding in std::function invokers.
* include/std/functional: (_Function_base::_Function_base()): Use nullptr instead of literal zero. (function::operator=(nullptr_t)): Likewise. (_Function_handler::_M_invoke): Use perfect forwarding for _ArgTypes. (function::_Invoker_type): Likewise. * testsuite/20_util/function/invoke/forwarding.cc: New. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@216849 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libstdc++-v3')
-rw-r--r--libstdc++-v3/ChangeLog9
-rw-r--r--libstdc++-v3/include/std/functional20
-rw-r--r--libstdc++-v3/testsuite/20_util/function/invoke/forwarding.cc56
3 files changed, 75 insertions, 10 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index e513ac7a5d5..08c44c3e552 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,5 +1,14 @@
2014-10-29 Jonathan Wakely <jwakely@redhat.com>
+ * include/std/functional: (_Function_base::_Function_base()): Use
+ nullptr instead of literal zero.
+ (function::operator=(nullptr_t)): Likewise.
+ (_Function_handler::_M_invoke): Use perfect forwarding for _ArgTypes.
+ (function::_Invoker_type): Likewise.
+ * testsuite/20_util/function/invoke/forwarding.cc: New.
+
+2014-10-29 Jonathan Wakely <jwakely@redhat.com>
+
* doc/xml/manual/status_cxx2014.xml: Update TS status.
* include/Makefile.am: Add new headers.
* include/Makefile.in: Regenerate.
diff --git a/libstdc++-v3/include/std/functional b/libstdc++-v3/include/std/functional
index bed1eea018f..5bc2730c2f5 100644
--- a/libstdc++-v3/include/std/functional
+++ b/libstdc++-v3/include/std/functional
@@ -1990,7 +1990,7 @@ _GLIBCXX_HAS_NESTED_TYPE(result_type)
}
};
- _Function_base() : _M_manager(0) { }
+ _Function_base() : _M_manager(nullptr) { }
~_Function_base()
{
@@ -2019,7 +2019,7 @@ _GLIBCXX_HAS_NESTED_TYPE(result_type)
public:
static _Res
- _M_invoke(const _Any_data& __functor, _ArgTypes... __args)
+ _M_invoke(const _Any_data& __functor, _ArgTypes&&... __args)
{
return (*_Base::_M_get_pointer(__functor))(
std::forward<_ArgTypes>(__args)...);
@@ -2034,7 +2034,7 @@ _GLIBCXX_HAS_NESTED_TYPE(result_type)
public:
static void
- _M_invoke(const _Any_data& __functor, _ArgTypes... __args)
+ _M_invoke(const _Any_data& __functor, _ArgTypes&&... __args)
{
(*_Base::_M_get_pointer(__functor))(
std::forward<_ArgTypes>(__args)...);
@@ -2049,7 +2049,7 @@ _GLIBCXX_HAS_NESTED_TYPE(result_type)
public:
static _Res
- _M_invoke(const _Any_data& __functor, _ArgTypes... __args)
+ _M_invoke(const _Any_data& __functor, _ArgTypes&&... __args)
{
return __callable_functor(**_Base::_M_get_pointer(__functor))(
std::forward<_ArgTypes>(__args)...);
@@ -2064,7 +2064,7 @@ _GLIBCXX_HAS_NESTED_TYPE(result_type)
public:
static void
- _M_invoke(const _Any_data& __functor, _ArgTypes... __args)
+ _M_invoke(const _Any_data& __functor, _ArgTypes&&... __args)
{
__callable_functor(**_Base::_M_get_pointer(__functor))(
std::forward<_ArgTypes>(__args)...);
@@ -2081,7 +2081,7 @@ _GLIBCXX_HAS_NESTED_TYPE(result_type)
public:
static _Res
- _M_invoke(const _Any_data& __functor, _ArgTypes... __args)
+ _M_invoke(const _Any_data& __functor, _ArgTypes&&... __args)
{
return std::mem_fn(_Base::_M_get_pointer(__functor)->__value)(
std::forward<_ArgTypes>(__args)...);
@@ -2121,7 +2121,7 @@ _GLIBCXX_HAS_NESTED_TYPE(result_type)
}
static void
- _M_invoke(const _Any_data& __functor, _ArgTypes... __args)
+ _M_invoke(const _Any_data& __functor, _ArgTypes&&... __args)
{
std::mem_fn(_Base::_M_get_pointer(__functor)->__value)(
std::forward<_ArgTypes>(__args)...);
@@ -2275,8 +2275,8 @@ _GLIBCXX_HAS_NESTED_TYPE(result_type)
if (_M_manager)
{
_M_manager(_M_functor, _M_functor, __destroy_functor);
- _M_manager = 0;
- _M_invoker = 0;
+ _M_manager = nullptr;
+ _M_invoker = nullptr;
}
return *this;
}
@@ -2395,7 +2395,7 @@ _GLIBCXX_HAS_NESTED_TYPE(result_type)
#endif
private:
- typedef _Res (*_Invoker_type)(const _Any_data&, _ArgTypes...);
+ using _Invoker_type = _Res (*)(const _Any_data&, _ArgTypes&&...);
_Invoker_type _M_invoker;
};
diff --git a/libstdc++-v3/testsuite/20_util/function/invoke/forwarding.cc b/libstdc++-v3/testsuite/20_util/function/invoke/forwarding.cc
new file mode 100644
index 00000000000..b6e1b47fb4a
--- /dev/null
+++ b/libstdc++-v3/testsuite/20_util/function/invoke/forwarding.cc
@@ -0,0 +1,56 @@
+// Copyright (C) 2014 Free Software Foundation, Inc.
+//
+// This file is part of the GNU ISO C++ Library. This library is free
+// software; you can redistribute it and/or modify it under the
+// terms of the GNU General Public License as published by the
+// Free Software Foundation; either version 3, or (at your option)
+// any later version.
+
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License along
+// with this library; see the file COPYING3. If not see
+// <http://www.gnu.org/licenses/>.
+
+// { dg-options "-std=gnu++11" }
+
+#include <functional>
+#include <testsuite_hooks.h>
+
+struct Counted
+{
+ Counted() : count(0) { }
+ Counted(const Counted& c) : count(c.count + 1) { }
+ int count;
+};
+
+int func(Counted c) { return c.count; }
+
+std::function<int(Counted)> f = func;
+
+void
+test01()
+{
+ Counted c;
+ int n = f(c);
+ // 1 copy invoking function::operator() and 1 copy invoking func
+ VERIFY( n == 2 );
+}
+
+void
+test02()
+{
+ int n = f(Counted{});
+ // copy elided when invoking function::operator(), 1 copy invoking func
+ VERIFY( n == 1 );
+}
+
+int
+main()
+{
+ test01();
+ test02();
+}