aboutsummaryrefslogtreecommitdiff
path: root/libstdc++-v3
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2022-04-25 14:22:41 +0100
committerJonathan Wakely <jwakely@redhat.com>2022-04-25 16:16:33 +0100
commita5cee0480c10bafa8ed65d49e5cedca23d98d7b7 (patch)
tree85183cccab9b63b13a1458d93ae1b2965ae73ea4 /libstdc++-v3
parent1ba397e9f93d3abc93a6ecbabc3d873489a6fb7f (diff)
downloadgcc-a5cee0480c10bafa8ed65d49e5cedca23d98d7b7.zip
gcc-a5cee0480c10bafa8ed65d49e5cedca23d98d7b7.tar.gz
gcc-a5cee0480c10bafa8ed65d49e5cedca23d98d7b7.tar.bz2
libstdc++: Add deduction guides for std::packaged_task [PR105375]
This change was LWG 3117. The test is copied from 20_util/function/cons/deduction.cc libstdc++-v3/ChangeLog: PR libstdc++/105375 * include/std/future (packaged_task): Add deduction guides. * testsuite/30_threads/packaged_task/cons/deduction.cc: New test.
Diffstat (limited to 'libstdc++-v3')
-rw-r--r--libstdc++-v3/include/std/future11
-rw-r--r--libstdc++-v3/testsuite/30_threads/packaged_task/cons/deduction.cc85
2 files changed, 96 insertions, 0 deletions
diff --git a/libstdc++-v3/include/std/future b/libstdc++-v3/include/std/future
index cba40dc..a9268ca 100644
--- a/libstdc++-v3/include/std/future
+++ b/libstdc++-v3/include/std/future
@@ -1622,6 +1622,17 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
}
};
+ // _GLIBCXX_RESOLVE_LIB_DEFECTS
+ // 3117. Missing packaged_task deduction guides
+#if __cpp_deduction_guides >= 201606
+ template<typename _Res, typename... _ArgTypes>
+ packaged_task(_Res(*)(_ArgTypes...)) -> packaged_task<_Res(_ArgTypes...)>;
+
+ template<typename _Fun, typename _Signature = typename
+ __function_guide_helper<decltype(&_Fun::operator())>::type>
+ packaged_task(_Fun) -> packaged_task<_Signature>;
+#endif
+
/// swap
template<typename _Res, typename... _ArgTypes>
inline void
diff --git a/libstdc++-v3/testsuite/30_threads/packaged_task/cons/deduction.cc b/libstdc++-v3/testsuite/30_threads/packaged_task/cons/deduction.cc
new file mode 100644
index 0000000..0eb6976
--- /dev/null
+++ b/libstdc++-v3/testsuite/30_threads/packaged_task/cons/deduction.cc
@@ -0,0 +1,85 @@
+// // Copyright (C) 2017-2022 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-do compile { target c++17 } }
+
+#include <future>
+
+template<typename T, typename U> struct require_same;
+template<typename T> struct require_same<T, T> { using type = void; };
+
+template<typename T, typename U>
+ typename require_same<T, U>::type
+ check_type(U&) { }
+
+void f0v();
+void f0vn() noexcept;
+int f0i();
+int f0in() noexcept;
+long f1l(int&);
+long f1ln(double*) noexcept;
+
+void
+test01()
+{
+ std::packaged_task task1{f0v};
+ check_type<std::packaged_task<void()>>(task1);
+
+ std::packaged_task task2{f0vn};
+ check_type<std::packaged_task<void()>>(task2);
+
+ std::packaged_task task3{f0i};
+ check_type<std::packaged_task<int()>>(task3);
+
+ std::packaged_task task4{f0in};
+ check_type<std::packaged_task<int()>>(task4);
+
+ std::packaged_task task5{f1l};
+ check_type<std::packaged_task<long(int&)>>(task5);
+
+ std::packaged_task task6{f1ln};
+ check_type<std::packaged_task<long(double*)>>(task6);
+
+ std::packaged_task task5a{std::move(task5)};
+ check_type<std::packaged_task<long(int&)>>(task5a);
+
+ std::packaged_task task6a{std::move(task6)};
+ check_type<std::packaged_task<long(double*)>>(task6a);
+}
+
+struct X {
+ int operator()(const short&, void*);
+};
+
+struct Y {
+ void operator()(int) const & noexcept;
+};
+
+void
+test02()
+{
+ X x;
+ std::packaged_task task1{x};
+ check_type<std::packaged_task<int(const short&, void*)>>(task1);
+
+ Y y;
+ std::packaged_task task2{y};
+ check_type<std::packaged_task<void(int)>>(task2);
+
+ std::packaged_task task3{[&x](float) -> X& { return x; }};
+ check_type<std::packaged_task<X&(float)>>(task3);
+}