blob: aa77dab51515fe79cc304ca98b3369844e6e1a8e [file] [log] [blame]
Howard Hinnantc52f43e2010-08-22 00:59:46 +00001//===----------------------------------------------------------------------===//
2//
3// The LLVM Compiler Infrastructure
4//
Howard Hinnantb64f8b02010-11-16 22:09:02 +00005// This file is dual licensed under the MIT and the University of Illinois Open
6// Source Licenses. See LICENSE.TXT for details.
Howard Hinnantc52f43e2010-08-22 00:59:46 +00007//
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>
Marshall Clow1b921882013-12-03 00:18:10 +000021#include "test_allocator.h"
Eric Fiselier4e7d5362014-10-23 04:12:28 +000022#include "min_allocator.h"
Howard Hinnantc52f43e2010-08-22 00:59:46 +000023
24int new_count = 0;
25
26struct A
27{
28 static int count;
29
30 A(int i, char c) : int_(i), char_(c) {++count;}
31 A(const A& a)
32 : int_(a.int_), char_(a.char_)
33 {++count;}
34 ~A() {--count;}
35
36 int get_int() const {return int_;}
37 char get_char() const {return char_;}
38private:
39 int int_;
40 char char_;
41};
42
43int A::count = 0;
44
45int main()
46{
47 {
48 int i = 67;
49 char c = 'e';
50 std::shared_ptr<A> p = std::allocate_shared<A>(test_allocator<A>(54), i, c);
51 assert(test_allocator<A>::alloc_count == 1);
52 assert(A::count == 1);
53 assert(p->get_int() == 67);
54 assert(p->get_char() == 'e');
55 }
56 assert(A::count == 0);
57 assert(test_allocator<A>::alloc_count == 0);
Dan Albert1d4a1ed2016-05-25 22:36:09 -070058#if __cplusplus >= 201103L
Eric Fiselier4e7d5362014-10-23 04:12:28 +000059 {
60 int i = 67;
61 char c = 'e';
62 std::shared_ptr<A> p = std::allocate_shared<A>(min_allocator<void>(), i, c);
63 assert(A::count == 1);
64 assert(p->get_int() == 67);
65 assert(p->get_char() == 'e');
66 }
67 assert(A::count == 0);
68 {
69 int i = 68;
70 char c = 'f';
71 std::shared_ptr<A> p = std::allocate_shared<A>(bare_allocator<void>(), i, c);
72 assert(A::count == 1);
73 assert(p->get_int() == 68);
74 assert(p->get_char() == 'f');
75 }
76 assert(A::count == 0);
Dan Albert1d4a1ed2016-05-25 22:36:09 -070077#endif
Howard Hinnantc52f43e2010-08-22 00:59:46 +000078}