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 // template <class OuterAlloc, class... InnerAllocs> 13 // class scoped_allocator_adaptor 14 15 // template <class T> void destroy(T* p); 16 17 #include <scoped_allocator> 18 #include <cassert> 19 #include <string> 20 21 #include "allocators.h" 22 23 struct B 24 { 25 static bool constructed; 26 BB27 B() {constructed = true;} ~BB28 ~B() {constructed = false;} 29 }; 30 31 bool B::constructed = false; 32 main()33int main() 34 { 35 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 36 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 69 #endif // _LIBCPP_HAS_NO_RVALUE_REFERENCES 70 } 71