Home | History | Annotate | Download | only in coroutine.handle.capacity
      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 // constexpr explicit operator bool() const noexcept
     19 
     20 #include <experimental/coroutine>
     21 #include <type_traits>
     22 #include <cassert>
     23 
     24 #include "test_macros.h"
     25 
     26 namespace coro = std::experimental;
     27 
     28 template <class C>
     29 void do_test() {
     30   static_assert(std::is_nothrow_constructible<bool, C>::value, "");
     31   static_assert(!std::is_convertible<C, bool>::value, "");
     32   {
     33     constexpr C c; ((void)c);
     34     static_assert(bool(c) == false, "");
     35   }
     36   { // null case
     37     const C c = {}; ((void)c);
     38     ASSERT_NOEXCEPT(bool(c));
     39     if (c)
     40       assert(false);
     41     else
     42       assert(true);
     43     assert(c.address() == nullptr);
     44     assert(bool(c) == false);
     45   }
     46   { // non-null case
     47     char dummy = 42;
     48     C c = C::from_address((void*)&dummy);
     49     assert(c.address() == &dummy);
     50     assert(bool(c) == true);
     51   }
     52 }
     53 
     54 int main()
     55 {
     56   do_test<coro::coroutine_handle<>>();
     57   do_test<coro::coroutine_handle<int>>();
     58 }
     59