• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // -*- C++ -*-
2 //===----------------------------------------------------------------------===//
3 //
4 //                     The LLVM Compiler Infrastructure
5 //
6 // This file is dual licensed under the MIT and the University of Illinois Open
7 // Source Licenses. See LICENSE.TXT for details.
8 //
9 //===----------------------------------------------------------------------===//
10 
11 // UNSUPPORTED: c++98, c++03, c++11
12 
13 // <experimental/coroutine>
14 
15 // template <class Promise = void>
16 // struct coroutine_handle;
17 
18 // void operator()()
19 // void resume()
20 
21 #include <experimental/coroutine>
22 #include <type_traits>
23 #include <memory>
24 #include <utility>
25 #include <cstdint>
26 #include <cassert>
27 
28 #include "test_macros.h"
29 
30 namespace coro = std::experimental;
31 
32 
33 template <class H>
34 auto has_resume_imp(H&& h, int) -> decltype(h.resume(), std::true_type{});
35 template <class H>
36 auto has_resume_imp(H&&, long) -> std::false_type;
37 
38 template <class H>
has_resume()39 constexpr bool has_resume() {
40   return decltype(has_resume_imp(std::declval<H>(), 0))::value;
41 }
42 
43 
44 template <class H>
45 auto has_call_operator_imp(H&& h, int) -> decltype(h(), std::true_type{});
46 template <class H>
47 auto has_call_operator_imp(H&&, long) -> std::false_type;
48 
49 template <class H>
has_call_operator()50 constexpr bool has_call_operator() {
51   return decltype(has_call_operator_imp(std::declval<H>(), 0))::value;
52 }
53 
54 template <class Promise>
do_test(coro::coroutine_handle<Promise> && H)55 void do_test(coro::coroutine_handle<Promise>&& H) {
56   using HType = coro::coroutine_handle<Promise>;
57   // FIXME Add a runtime test
58   {
59     ASSERT_SAME_TYPE(decltype(H.resume()), void);
60     ASSERT_SAME_TYPE(decltype(H()), void);
61     LIBCPP_ASSERT_NOT_NOEXCEPT(H.resume());
62     LIBCPP_ASSERT_NOT_NOEXCEPT(H());
63     static_assert(has_resume<HType&>(), "");
64     static_assert(has_resume<HType&&>(), "");
65     static_assert(has_call_operator<HType&>(), "");
66     static_assert(has_call_operator<HType&&>(), "");
67   }
68   {
69     static_assert(!has_resume<HType const&>(), "");
70     static_assert(!has_resume<HType const&&>(), "");
71     static_assert(!has_call_operator<HType const&>(), "");
72     static_assert(!has_call_operator<HType const&&>(), "");
73   }
74 }
75 
main()76 int main()
77 {
78   do_test(coro::coroutine_handle<>{});
79   do_test(coro::coroutine_handle<int>{});
80 }
81