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(promise&& rhs); 15 16 #include <future> 17 #include <cassert> 18 19 #include "../test_allocator.h" 20 21 int main() 22 { 23 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 24 assert(test_alloc_base::count == 0); 25 { 26 std::promise<int> p0(std::allocator_arg, test_allocator<int>()); 27 std::promise<int> p(std::move(p0)); 28 assert(test_alloc_base::count == 1); 29 std::future<int> f = p.get_future(); 30 assert(test_alloc_base::count == 1); 31 assert(f.valid()); 32 try 33 { 34 f = p0.get_future(); 35 assert(false); 36 } 37 catch (const std::future_error& e) 38 { 39 assert(e.code() == make_error_code(std::future_errc::no_state)); 40 } 41 assert(test_alloc_base::count == 1); 42 } 43 assert(test_alloc_base::count == 0); 44 { 45 std::promise<int&> p0(std::allocator_arg, test_allocator<int>()); 46 std::promise<int&> p(std::move(p0)); 47 assert(test_alloc_base::count == 1); 48 std::future<int&> f = p.get_future(); 49 assert(test_alloc_base::count == 1); 50 assert(f.valid()); 51 try 52 { 53 f = p0.get_future(); 54 assert(false); 55 } 56 catch (const std::future_error& e) 57 { 58 assert(e.code() == make_error_code(std::future_errc::no_state)); 59 } 60 assert(test_alloc_base::count == 1); 61 } 62 assert(test_alloc_base::count == 0); 63 { 64 std::promise<void> p0(std::allocator_arg, test_allocator<void>()); 65 std::promise<void> p(std::move(p0)); 66 assert(test_alloc_base::count == 1); 67 std::future<void> f = p.get_future(); 68 assert(test_alloc_base::count == 1); 69 assert(f.valid()); 70 try 71 { 72 f = p0.get_future(); 73 assert(false); 74 } 75 catch (const std::future_error& e) 76 { 77 assert(e.code() == make_error_code(std::future_errc::no_state)); 78 } 79 assert(test_alloc_base::count == 1); 80 } 81 assert(test_alloc_base::count == 0); 82 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 83 } 84