]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - test/std/utilities/memory/allocator.traits/allocator.traits.members/select_on_container_copy_construction.pass.cpp
Vendor import of libc++ trunk r290819:
[FreeBSD/FreeBSD.git] / test / std / utilities / memory / allocator.traits / allocator.traits.members / select_on_container_copy_construction.pass.cpp
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
27 template <class T>
28 struct A
29 {
30     typedef T value_type;
31     int id;
32     explicit A(int i = 0) : id(i) {}
33
34 };
35
36 template <class T>
37 struct B
38 {
39     typedef T value_type;
40
41     int id;
42     explicit B(int i = 0) : id(i) {}
43
44     B select_on_container_copy_construction() const
45     {
46         return B(100);
47     }
48 };
49
50 int main()
51 {
52     {
53         A<int> a;
54         assert(std::allocator_traits<A<int> >::select_on_container_copy_construction(a).id == 0);
55     }
56     {
57         const A<int> a(0);
58         assert(std::allocator_traits<A<int> >::select_on_container_copy_construction(a).id == 0);
59     }
60 #if TEST_STD_VER >= 11
61     {
62         B<int> b;
63         assert(std::allocator_traits<B<int> >::select_on_container_copy_construction(b).id == 100);
64     }
65     {
66         const B<int> b(0);
67         assert(std::allocator_traits<B<int> >::select_on_container_copy_construction(b).id == 100);
68     }
69 #endif
70 }