xref: /llvm-project/libcxx/test/std/thread/futures/futures.task/futures.task.members/ctad.compile.pass.cpp (revision 3ec6c997c67d685c533b8c9c2cffde31d834b821)
1*3ec6c997SNikolas Klauser //===----------------------------------------------------------------------===//
2*3ec6c997SNikolas Klauser //
3*3ec6c997SNikolas Klauser // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4*3ec6c997SNikolas Klauser // See https://llvm.org/LICENSE.txt for license information.
5*3ec6c997SNikolas Klauser // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6*3ec6c997SNikolas Klauser //
7*3ec6c997SNikolas Klauser //===----------------------------------------------------------------------===//
8*3ec6c997SNikolas Klauser 
9*3ec6c997SNikolas Klauser // UNSUPPORTED: no-threads
10*3ec6c997SNikolas Klauser // UNSUPPORTED: c++03, c++11, c++14
11*3ec6c997SNikolas Klauser 
12*3ec6c997SNikolas Klauser // checks that CTAD works properly
13*3ec6c997SNikolas Klauser 
14*3ec6c997SNikolas Klauser #include <future>
15*3ec6c997SNikolas Klauser #include <type_traits>
16*3ec6c997SNikolas Klauser 
17*3ec6c997SNikolas Klauser int func(char*);
18*3ec6c997SNikolas Klauser static_assert(std::is_same_v<decltype(std::packaged_task{func}), std::packaged_task<int(char*)>>);
19*3ec6c997SNikolas Klauser 
20*3ec6c997SNikolas Klauser int funcn(char*) noexcept;
21*3ec6c997SNikolas Klauser static_assert(std::is_same_v<decltype(std::packaged_task{funcn}), std::packaged_task<int(char*)>>);
22*3ec6c997SNikolas Klauser 
23*3ec6c997SNikolas Klauser template <bool Noexcept>
24*3ec6c997SNikolas Klauser struct Callable {
25*3ec6c997SNikolas Klauser   int operator()(char*) noexcept(Noexcept);
26*3ec6c997SNikolas Klauser };
27*3ec6c997SNikolas Klauser static_assert(std::is_same_v<decltype(std::packaged_task{Callable<true>{}}), std::packaged_task<int(char*)>>);
28*3ec6c997SNikolas Klauser static_assert(std::is_same_v<decltype(std::packaged_task{Callable<false>{}}), std::packaged_task<int(char*)>>);
29*3ec6c997SNikolas Klauser 
30*3ec6c997SNikolas Klauser template <bool Noexcept>
31*3ec6c997SNikolas Klauser struct CallableC {
32*3ec6c997SNikolas Klauser   int operator()(char*) const noexcept(Noexcept);
33*3ec6c997SNikolas Klauser };
34*3ec6c997SNikolas Klauser static_assert(std::is_same_v<decltype(std::packaged_task{CallableC<true>{}}), std::packaged_task<int(char*)>>);
35*3ec6c997SNikolas Klauser static_assert(std::is_same_v<decltype(std::packaged_task{CallableC<false>{}}), std::packaged_task<int(char*)>>);
36*3ec6c997SNikolas Klauser 
37*3ec6c997SNikolas Klauser template <bool Noexcept>
38*3ec6c997SNikolas Klauser struct CallableV {
39*3ec6c997SNikolas Klauser   int operator()(char*) const noexcept(Noexcept);
40*3ec6c997SNikolas Klauser };
41*3ec6c997SNikolas Klauser static_assert(std::is_same_v<decltype(std::packaged_task{CallableV<true>{}}), std::packaged_task<int(char*)>>);
42*3ec6c997SNikolas Klauser static_assert(std::is_same_v<decltype(std::packaged_task{CallableV<false>{}}), std::packaged_task<int(char*)>>);
43*3ec6c997SNikolas Klauser 
44*3ec6c997SNikolas Klauser template <bool Noexcept>
45*3ec6c997SNikolas Klauser struct CallableCV {
46*3ec6c997SNikolas Klauser   int operator()(char*) const volatile noexcept(Noexcept);
47*3ec6c997SNikolas Klauser };
48*3ec6c997SNikolas Klauser static_assert(std::is_same_v<decltype(std::packaged_task{CallableCV<true>{}}), std::packaged_task<int(char*)>>);
49*3ec6c997SNikolas Klauser static_assert(std::is_same_v<decltype(std::packaged_task{CallableCV<false>{}}), std::packaged_task<int(char*)>>);
50*3ec6c997SNikolas Klauser 
51*3ec6c997SNikolas Klauser template <bool Noexcept>
52*3ec6c997SNikolas Klauser struct CallableL {
53*3ec6c997SNikolas Klauser   int operator()(char*) & noexcept(Noexcept);
54*3ec6c997SNikolas Klauser };
55*3ec6c997SNikolas Klauser static_assert(std::is_same_v<decltype(std::packaged_task{CallableL<true>{}}), std::packaged_task<int(char*)>>);
56*3ec6c997SNikolas Klauser static_assert(std::is_same_v<decltype(std::packaged_task{CallableL<false>{}}), std::packaged_task<int(char*)>>);
57*3ec6c997SNikolas Klauser 
58*3ec6c997SNikolas Klauser template <bool Noexcept>
59*3ec6c997SNikolas Klauser struct CallableCL {
60*3ec6c997SNikolas Klauser   int operator()(char*) const & noexcept(Noexcept);
61*3ec6c997SNikolas Klauser };
62*3ec6c997SNikolas Klauser static_assert(std::is_same_v<decltype(std::packaged_task{CallableCL<true>{}}), std::packaged_task<int(char*)>>);
63*3ec6c997SNikolas Klauser static_assert(std::is_same_v<decltype(std::packaged_task{CallableCL<false>{}}), std::packaged_task<int(char*)>>);
64*3ec6c997SNikolas Klauser 
65*3ec6c997SNikolas Klauser template <bool Noexcept>
66*3ec6c997SNikolas Klauser struct CallableVL {
67*3ec6c997SNikolas Klauser   int operator()(char*) const noexcept(Noexcept);
68*3ec6c997SNikolas Klauser };
69*3ec6c997SNikolas Klauser static_assert(std::is_same_v<decltype(std::packaged_task{CallableVL<true>{}}), std::packaged_task<int(char*)>>);
70*3ec6c997SNikolas Klauser static_assert(std::is_same_v<decltype(std::packaged_task{CallableVL<false>{}}), std::packaged_task<int(char*)>>);
71*3ec6c997SNikolas Klauser 
72*3ec6c997SNikolas Klauser template <bool Noexcept>
73*3ec6c997SNikolas Klauser struct CallableCVL {
74*3ec6c997SNikolas Klauser   int operator()(char*) const volatile & noexcept(Noexcept);
75*3ec6c997SNikolas Klauser };
76*3ec6c997SNikolas Klauser static_assert(std::is_same_v<decltype(std::packaged_task{CallableCVL<true>{}}), std::packaged_task<int(char*)>>);
77*3ec6c997SNikolas Klauser static_assert(std::is_same_v<decltype(std::packaged_task{CallableCVL<false>{}}), std::packaged_task<int(char*)>>);
78