xref: /llvm-project/libcxx/test/std/thread/futures/futures.shared_future/dtor.pass.cpp (revision a7f9895cc18995549c7facb96e72718da282a864)
15a83710eSEric Fiselier //===----------------------------------------------------------------------===//
25a83710eSEric Fiselier //
357b08b09SChandler Carruth // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
457b08b09SChandler Carruth // See https://llvm.org/LICENSE.txt for license information.
557b08b09SChandler Carruth // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
65a83710eSEric Fiselier //
75a83710eSEric Fiselier //===----------------------------------------------------------------------===//
85a83710eSEric Fiselier //
98c61114cSLouis Dionne // UNSUPPORTED: no-exceptions
10*a7f9895cSLouis Dionne // UNSUPPORTED: no-threads
1131cbe0f2SLouis Dionne // UNSUPPORTED: c++03
125a83710eSEric Fiselier 
135a83710eSEric Fiselier // <future>
145a83710eSEric Fiselier 
155a83710eSEric Fiselier // class shared_future<R>
165a83710eSEric Fiselier 
175a83710eSEric Fiselier // ~shared_future();
185a83710eSEric Fiselier 
195a83710eSEric Fiselier #include <future>
205a83710eSEric Fiselier #include <cassert>
215a83710eSEric Fiselier 
227fc6a556SMarshall Clow #include "test_macros.h"
23cb38f75eSEric Fiselier #include "test_allocator.h"
245a83710eSEric Fiselier 
main(int,char **)252df59c50SJF Bastien int main(int, char**)
265a83710eSEric Fiselier {
279a140a15SNikolas Klauser     test_allocator_statistics alloc_stats;
289a140a15SNikolas Klauser     assert(alloc_stats.alloc_count == 0);
295a83710eSEric Fiselier     {
305a83710eSEric Fiselier         typedef int T;
315a83710eSEric Fiselier         std::shared_future<T> f;
325a83710eSEric Fiselier         {
339a140a15SNikolas Klauser             std::promise<T> p(std::allocator_arg, test_allocator<T>(&alloc_stats));
349a140a15SNikolas Klauser             assert(alloc_stats.alloc_count == 1);
355a83710eSEric Fiselier             f = p.get_future();
369a140a15SNikolas Klauser             assert(alloc_stats.alloc_count == 1);
375a83710eSEric Fiselier             assert(f.valid());
385a83710eSEric Fiselier         }
399a140a15SNikolas Klauser         assert(alloc_stats.alloc_count == 1);
405a83710eSEric Fiselier         assert(f.valid());
415a83710eSEric Fiselier     }
429a140a15SNikolas Klauser     assert(alloc_stats.alloc_count == 0);
435a83710eSEric Fiselier     {
445a83710eSEric Fiselier         typedef int& T;
455a83710eSEric Fiselier         std::shared_future<T> f;
465a83710eSEric Fiselier         {
479a140a15SNikolas Klauser             std::promise<T> p(std::allocator_arg, test_allocator<int>(&alloc_stats));
489a140a15SNikolas Klauser             assert(alloc_stats.alloc_count == 1);
495a83710eSEric Fiselier             f = p.get_future();
509a140a15SNikolas Klauser             assert(alloc_stats.alloc_count == 1);
515a83710eSEric Fiselier             assert(f.valid());
525a83710eSEric Fiselier         }
539a140a15SNikolas Klauser         assert(alloc_stats.alloc_count == 1);
545a83710eSEric Fiselier         assert(f.valid());
555a83710eSEric Fiselier     }
569a140a15SNikolas Klauser     assert(alloc_stats.alloc_count == 0);
575a83710eSEric Fiselier     {
585a83710eSEric Fiselier         typedef void T;
595a83710eSEric Fiselier         std::shared_future<T> f;
605a83710eSEric Fiselier         {
619a140a15SNikolas Klauser             std::promise<T> p(std::allocator_arg, test_allocator<T>(&alloc_stats));
629a140a15SNikolas Klauser             assert(alloc_stats.alloc_count == 1);
635a83710eSEric Fiselier             f = p.get_future();
649a140a15SNikolas Klauser             assert(alloc_stats.alloc_count == 1);
655a83710eSEric Fiselier             assert(f.valid());
665a83710eSEric Fiselier         }
679a140a15SNikolas Klauser         assert(alloc_stats.alloc_count == 1);
685a83710eSEric Fiselier         assert(f.valid());
695a83710eSEric Fiselier     }
709a140a15SNikolas Klauser     assert(alloc_stats.alloc_count == 0);
712df59c50SJF Bastien 
722df59c50SJF Bastien   return 0;
735a83710eSEric Fiselier }
74