Home | History | Annotate | Download | only in futures.shared_future
      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 // UNSUPPORTED: libcpp-no-exceptions
     11 // UNSUPPORTED: libcpp-has-no-threads
     12 // UNSUPPORTED: c++98, c++03
     13 
     14 // <future>
     15 
     16 // class shared_future<R>
     17 
     18 // ~shared_future();
     19 
     20 #include <future>
     21 #include <cassert>
     22 
     23 #include "test_allocator.h"
     24 
     25 int main()
     26 {
     27     assert(test_alloc_base::alloc_count == 0);
     28     {
     29         typedef int T;
     30         std::shared_future<T> f;
     31         {
     32             std::promise<T> p(std::allocator_arg, test_allocator<T>());
     33             assert(test_alloc_base::alloc_count == 1);
     34             f = p.get_future();
     35             assert(test_alloc_base::alloc_count == 1);
     36             assert(f.valid());
     37         }
     38         assert(test_alloc_base::alloc_count == 1);
     39         assert(f.valid());
     40     }
     41     assert(test_alloc_base::alloc_count == 0);
     42     {
     43         typedef int& T;
     44         std::shared_future<T> f;
     45         {
     46             std::promise<T> p(std::allocator_arg, test_allocator<int>());
     47             assert(test_alloc_base::alloc_count == 1);
     48             f = p.get_future();
     49             assert(test_alloc_base::alloc_count == 1);
     50             assert(f.valid());
     51         }
     52         assert(test_alloc_base::alloc_count == 1);
     53         assert(f.valid());
     54     }
     55     assert(test_alloc_base::alloc_count == 0);
     56     {
     57         typedef void T;
     58         std::shared_future<T> f;
     59         {
     60             std::promise<T> p(std::allocator_arg, test_allocator<T>());
     61             assert(test_alloc_base::alloc_count == 1);
     62             f = p.get_future();
     63             assert(test_alloc_base::alloc_count == 1);
     64             assert(f.valid());
     65         }
     66         assert(test_alloc_base::alloc_count == 1);
     67         assert(f.valid());
     68     }
     69     assert(test_alloc_base::alloc_count == 0);
     70 }
     71