allocate_shared.pass.cpp revision 1b92188a82b01e76ac6e8ad5f997293c2a078adc
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 23int new_count = 0; 24 25struct A 26{ 27 static int count; 28 29 A(int i, char c) : int_(i), char_(c) {++count;} 30 A(const A& a) 31 : int_(a.int_), char_(a.char_) 32 {++count;} 33 ~A() {--count;} 34 35 int get_int() const {return int_;} 36 char get_char() const {return char_;} 37private: 38 int int_; 39 char char_; 40}; 41 42int A::count = 0; 43 44int 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