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