Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
Howard Hinnant | b64f8b0 | 2010-11-16 22:09:02 +0000 | [diff] [blame] | 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 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> |
Marshall Clow | 1b92188 | 2013-12-03 00:18:10 +0000 | [diff] [blame] | 21 | #include "test_allocator.h" |
Eric Fiselier | 4e7d536 | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 22 | #include "min_allocator.h" |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 23 | |
| 24 | int new_count = 0; |
| 25 | |
| 26 | struct 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_;} |
| 38 | private: |
| 39 | int int_; |
| 40 | char char_; |
| 41 | }; |
| 42 | |
| 43 | int A::count = 0; |
| 44 | |
| 45 | int 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 Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 58 | #if __cplusplus >= 201103L |
Eric Fiselier | 4e7d536 | 2014-10-23 04:12:28 +0000 | [diff] [blame] | 59 | { |
| 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 Albert | 1d4a1ed | 2016-05-25 22:36:09 -0700 | [diff] [blame^] | 77 | #endif |
Howard Hinnant | c52f43e | 2010-08-22 00:59:46 +0000 | [diff] [blame] | 78 | } |