blob: 12c415f6d6221df12ac41482d95cfe7dc4bcf492 [file] [log] [blame]
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00001//===----------------------------------------------------------------------===//
2//
Howard Hinnantf5256e12010-05-11 21:36:01 +00003// The LLVM Compiler Infrastructure
Howard Hinnantbc8d3f92010-05-11 19:42:16 +00004//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10// <memory>
11
12// template <class OuterAlloc, class... InnerAllocs>
13// class scoped_allocator_adaptor
14
15// template <class T> void destroy(T* p);
16
Howard Hinnante92c3d72010-08-19 18:39:17 +000017#include <scoped_allocator>
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000018#include <cassert>
19#include <string>
20
21#include "../allocators.h"
22
23struct B
24{
25 static bool constructed;
26
27 B() {constructed = true;}
28 ~B() {constructed = false;}
29};
30
31bool B::constructed = false;
32
33int main()
34{
Howard Hinnant73d21a42010-09-04 23:28:19 +000035#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000036
37 {
38 typedef std::scoped_allocator_adaptor<A1<B>> A;
39 A a;
40 char buf[100];
41 typedef B S;
42 S* s = (S*)buf;
43 assert(!S::constructed);
44 a.construct(s);
45 assert(S::constructed);
46 a.destroy(s);
47 assert(!S::constructed);
48 }
49
50 {
51 typedef std::scoped_allocator_adaptor<A3<B>, A1<B>> A;
52 A a;
53 char buf[100];
54 typedef B S;
55 S* s = (S*)buf;
56 assert(!S::constructed);
57 assert(!A3<S>::constructed);
58 assert(!A3<S>::destroy_called);
59 a.construct(s);
60 assert(S::constructed);
61 assert(A3<S>::constructed);
62 assert(!A3<S>::destroy_called);
63 a.destroy(s);
64 assert(!S::constructed);
65 assert(A3<S>::constructed);
66 assert(A3<S>::destroy_called);
67 }
68
Howard Hinnant73d21a42010-09-04 23:28:19 +000069#endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES
Howard Hinnantbc8d3f92010-05-11 19:42:16 +000070}