select_on_container_copy_construction.pass.cpp revision bc8d3f97eb5c958007f2713238472e0c1c8fe02c
1//===----------------------------------------------------------------------===// 2// 3// ��������������������The LLVM Compiler Infrastructure 4// 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 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 25template <class T> 26struct A 27{ 28 typedef T value_type; 29 int id; 30 explicit A(int i = 0) : id(i) {} 31 32}; 33 34template <class T> 35struct B 36{ 37 typedef T value_type; 38 39 int id; 40 explicit B(int i = 0) : id(i) {} 41 42 B select_on_container_copy_construction() const 43 { 44 return B(100); 45 } 46}; 47 48int main() 49{ 50 { 51 A<int> a; 52 assert(std::allocator_traits<A<int> >::select_on_container_copy_construction(a).id == 0); 53 } 54 { 55 const A<int> a(0); 56 assert(std::allocator_traits<A<int> >::select_on_container_copy_construction(a).id == 0); 57 } 58#ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE 59 { 60 B<int> b; 61 assert(std::allocator_traits<B<int> >::select_on_container_copy_construction(b).id == 100); 62 } 63 { 64 const B<int> b(0); 65 assert(std::allocator_traits<B<int> >::select_on_container_copy_construction(b).id == 100); 66 } 67#endif 68} 69