• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // <memory>
11 
12 // shared_ptr
13 
14 // template<class T, class A, class... Args>
15 //    shared_ptr<T> allocate_shared(const A& a, Args&&... args);
16 
17 #include <memory>
18 #include <new>
19 #include <cstdlib>
20 #include <cassert>
21 #include "test_allocator.h"
22 
23 int new_count = 0;
24 
25 struct A
26 {
27     static int count;
28 
AA29     A(int i, char c) : int_(i), char_(c) {++count;}
AA30     A(const A& a)
31         : int_(a.int_), char_(a.char_)
32         {++count;}
~AA33     ~A() {--count;}
34 
get_intA35     int get_int() const {return int_;}
get_charA36     char get_char() const {return char_;}
37 private:
38     int int_;
39     char char_;
40 };
41 
42 int A::count = 0;
43 
main()44 int main()
45 {
46     {
47     int i = 67;
48     char c = 'e';
49     std::shared_ptr<A> p = std::allocate_shared<A>(test_allocator<A>(54), i, c);
50     assert(test_allocator<A>::alloc_count == 1);
51     assert(A::count == 1);
52     assert(p->get_int() == 67);
53     assert(p->get_char() == 'e');
54     }
55     assert(A::count == 0);
56     assert(test_allocator<A>::alloc_count == 0);
57 }
58