1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // <future> 11 12 // class promise<R> 13 14 // promise(const promise&) = delete; 15 16 #include <future> 17 #include <cassert> 18 19 #include "../test_allocator.h" 20 main()21int main() 22 { 23 assert(test_alloc_base::count == 0); 24 { 25 std::promise<int> p0(std::allocator_arg, test_allocator<int>()); 26 std::promise<int> p(p0); 27 assert(test_alloc_base::count == 1); 28 std::future<int> f = p.get_future(); 29 assert(test_alloc_base::count == 1); 30 assert(f.valid()); 31 try 32 { 33 f = p0.get_future(); 34 assert(false); 35 } 36 catch (const std::future_error& e) 37 { 38 assert(e.code() == make_error_code(std::future_errc::no_state)); 39 } 40 assert(test_alloc_base::count == 1); 41 } 42 assert(test_alloc_base::count == 0); 43 { 44 std::promise<int&> p0(std::allocator_arg, test_allocator<int>()); 45 std::promise<int&> p(p0); 46 assert(test_alloc_base::count == 1); 47 std::future<int&> f = p.get_future(); 48 assert(test_alloc_base::count == 1); 49 assert(f.valid()); 50 try 51 { 52 f = p0.get_future(); 53 assert(false); 54 } 55 catch (const std::future_error& e) 56 { 57 assert(e.code() == make_error_code(std::future_errc::no_state)); 58 } 59 assert(test_alloc_base::count == 1); 60 } 61 assert(test_alloc_base::count == 0); 62 { 63 std::promise<void> p0(std::allocator_arg, test_allocator<void>()); 64 std::promise<void> p(p0); 65 assert(test_alloc_base::count == 1); 66 std::future<void> f = p.get_future(); 67 assert(test_alloc_base::count == 1); 68 assert(f.valid()); 69 try 70 { 71 f = p0.get_future(); 72 assert(false); 73 } 74 catch (const std::future_error& e) 75 { 76 assert(e.code() == make_error_code(std::future_errc::no_state)); 77 } 78 assert(test_alloc_base::count == 1); 79 } 80 assert(test_alloc_base::count == 0); 81 } 82