77 lines · cpp
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-exception6//7//===----------------------------------------------------------------------===//8//9// UNSUPPORTED: no-threads10// UNSUPPORTED: c++0311 12// <future>13 14// class shared_future<R>15 16// shared_future(const shared_future& rhs);17// noexcept in C++1718 19#include <future>20#include <cassert>21 22#include "test_macros.h"23 24int main(int, char**)25{26 {27 typedef int T;28 std::promise<T> p;29 std::shared_future<T> f0 = p.get_future();30 std::shared_future<T> f = f0;31#if TEST_STD_VER > 1432 static_assert(noexcept(std::shared_future<T>{f0}), "" );33#endif34 assert(f0.valid());35 assert(f.valid());36 }37 {38 typedef int T;39 std::shared_future<T> f0;40 std::shared_future<T> f = f0;41 assert(!f0.valid());42 assert(!f.valid());43 }44 {45 typedef int& T;46 std::promise<T> p;47 std::shared_future<T> f0 = p.get_future();48 std::shared_future<T> f = f0;49 assert(f0.valid());50 assert(f.valid());51 }52 {53 typedef int& T;54 std::shared_future<T> f0;55 std::shared_future<T> f = std::move(f0);56 assert(!f0.valid());57 assert(!f.valid());58 }59 {60 typedef void T;61 std::promise<T> p;62 std::shared_future<T> f0 = p.get_future();63 std::shared_future<T> f = f0;64 assert(f0.valid());65 assert(f.valid());66 }67 {68 typedef void T;69 std::shared_future<T> f0;70 std::shared_future<T> f = f0;71 assert(!f0.valid());72 assert(!f.valid());73 }74 75 return 0;76}77