]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/allocator_traits/requirements/typedefs2.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / allocator_traits / requirements / typedefs2.cc
1 // { dg-do compile { target c++11 } }
2 //
3 // Copyright (C) 2013-2021 Free Software Foundation, Inc.
4 //
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
9 // any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
19
20 #include <memory>
21 #include <testsuite_allocator.h>
22
23 template<typename T>
24 struct ptr
25 {
26 ptr() = default;
27 template<typename U>
28 ptr(ptr<U> const& p) { }
29 };
30
31 // This doesn't meet the allocator requirements, it's only to check
32 // that allocator_traits finds the right nested types.
33 template<typename T>
34 struct alloc
35 {
36 typedef T value_type;
37
38 typedef ptr<T> pointer;
39 typedef ptr<const T> const_pointer;
40 typedef ptr<void> void_pointer;
41 typedef ptr<const void> const_void_pointer;
42 typedef int difference_type;
43 typedef int size_type;
44
45 typedef std::false_type propagate_on_container_copy_assignment;
46 typedef std::false_type propagate_on_container_move_assignment;
47 typedef std::false_type propagate_on_container_swap;
48 };
49
50 typedef alloc<int> alloc_type;
51 typedef std::allocator_traits<alloc_type> traits;
52
53 using std::is_same;
54
55 static_assert( is_same<traits::pointer, alloc_type::pointer>::value,
56 "pointer" );
57
58 static_assert( is_same<traits::const_pointer,
59 alloc_type::const_pointer>::value,
60 "const_pointer" );
61
62 static_assert( is_same<traits::void_pointer, alloc_type::void_pointer>::value,
63 "void_pointer" );
64
65 static_assert( is_same<traits::const_void_pointer,
66 alloc_type::const_void_pointer>::value,
67 "const_void_pointer");
68
69 static_assert( is_same<traits::difference_type,
70 alloc_type::difference_type>::value,
71 "difference_type" );
72
73 static_assert( is_same<traits::size_type, alloc_type::size_type>::value,
74 "size_type" );
75
76 static_assert( is_same<traits::size_type, alloc_type::size_type>::value,
77 "size_type" );
78
79 static_assert( is_same<traits::propagate_on_container_copy_assignment,
80 alloc_type::propagate_on_container_copy_assignment
81 >::value,
82 "propagate_on_container_copy_assignment" );
83
84 static_assert( is_same<traits::propagate_on_container_move_assignment,
85 alloc_type::propagate_on_container_move_assignment
86 >::value,
87 "propagate_on_container_move_assignment" );
88
89 static_assert( is_same<traits::propagate_on_container_swap,
90 alloc_type::propagate_on_container_swap>::value,
91 "propagate_on_container_swap" );