1 //===----------------------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // UNSUPPORTED: libcpp-has-no-threads 10 // UNSUPPORTED: c++98, c++03 11 12 // <future> 13 14 // class future<R> 15 16 // shared_future<R> share() &&; 17 18 #include <future> 19 #include <cassert> 20 21 int main(int, char**) 22 { 23 { 24 typedef int T; 25 std::promise<T> p; 26 std::future<T> f0 = p.get_future(); 27 static_assert( noexcept(f0.share()), ""); 28 std::shared_future<T> f = f0.share(); 29 assert(!f0.valid()); 30 assert(f.valid()); 31 } 32 { 33 typedef int T; 34 std::future<T> f0; 35 static_assert( noexcept(f0.share()), ""); 36 std::shared_future<T> f = f0.share(); 37 assert(!f0.valid()); 38 assert(!f.valid()); 39 } 40 { 41 typedef int& T; 42 std::promise<T> p; 43 std::future<T> f0 = p.get_future(); 44 static_assert( noexcept(f0.share()), ""); 45 std::shared_future<T> f = f0.share(); 46 assert(!f0.valid()); 47 assert(f.valid()); 48 } 49 { 50 typedef int& T; 51 std::future<T> f0; 52 static_assert( noexcept(f0.share()), ""); 53 std::shared_future<T> f = f0.share(); 54 assert(!f0.valid()); 55 assert(!f.valid()); 56 } 57 { 58 typedef void T; 59 std::promise<T> p; 60 std::future<T> f0 = p.get_future(); 61 static_assert( noexcept(f0.share()), ""); 62 std::shared_future<T> f = f0.share(); 63 assert(!f0.valid()); 64 assert(f.valid()); 65 } 66 { 67 typedef void T; 68 std::future<T> f0; 69 static_assert( noexcept(f0.share()), ""); 70 std::shared_future<T> f = f0.share(); 71 assert(!f0.valid()); 72 assert(!f.valid()); 73 } 74 75 return 0; 76 } 77