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 Alloc> 13 // struct allocator_traits 14 // { 15 // static allocator_type 16 // select_on_container_copy_construction(const allocator_type& a); 17 // ... 18 // }; 19 20 #include <memory> 21 #include <new> 22 #include <type_traits> 23 #include <cassert> 24 25 #include "test_macros.h" 26 #include "incomplete_type_helper.h" 27 28 template <class T> 29 struct A 30 { 31 typedef T value_type; 32 int id; 33 explicit A(int i = 0) : id(i) {} 34 35 }; 36 37 template <class T> 38 struct B 39 { 40 typedef T value_type; 41 42 int id; 43 explicit B(int i = 0) : id(i) {} 44 45 B select_on_container_copy_construction() const 46 { 47 return B(100); 48 } 49 }; 50 51 int main() 52 { 53 { 54 A<int> a; 55 assert(std::allocator_traits<A<int> >::select_on_container_copy_construction(a).id == 0); 56 } 57 { 58 const A<int> a(0); 59 assert(std::allocator_traits<A<int> >::select_on_container_copy_construction(a).id == 0); 60 } 61 { 62 typedef IncompleteHolder* VT; 63 typedef A<VT> Alloc; 64 Alloc a; 65 assert(std::allocator_traits<Alloc>::select_on_container_copy_construction(a).id == 0); 66 } 67 #if TEST_STD_VER >= 11 68 { 69 B<int> b; 70 assert(std::allocator_traits<B<int> >::select_on_container_copy_construction(b).id == 100); 71 } 72 { 73 const B<int> b(0); 74 assert(std::allocator_traits<B<int> >::select_on_container_copy_construction(b).id == 100); 75 } 76 #endif 77 } 78