]> git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/allocator_traits/members/is_always_equal.cc
Update copyright years.
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / allocator_traits / members / is_always_equal.cc
1 // Copyright (C) 2015-2020 Free Software Foundation, Inc.
2 //
3 // This file is part of the GNU ISO C++ Library. This library is free
4 // software; you can redistribute it and/or modify it under the
5 // terms of the GNU General Public License as published by the
6 // Free Software Foundation; either version 3, or (at your option)
7 // any later version.
8
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13
14 // You should have received a copy of the GNU General Public License along
15 // with this library; see the file COPYING3. If not see
16 // <http://www.gnu.org/licenses/>.
17
18 // { dg-do compile { target c++11 } }
19
20 #include <type_traits>
21 #include <memory>
22
23 template<typename T, typename Base>
24 struct Alloc : Base
25 {
26 typedef T value_type;
27 Alloc();
28 template <typename U>
29 Alloc(const Alloc<U, Base>&);
30 T* allocate(std::size_t);
31 void deallocate(T*, std::size_t);
32 };
33
34 template<bool> struct Empty { };
35 template<> struct Empty<false> { int x; };
36
37 template<bool B>
38 struct WithType
39 { using is_always_equal = std::integral_constant<bool, B>; };
40
41 struct EmptyAndTrue : Empty<true>, WithType<true> { };
42 struct EmptyButFalse : Empty<true>, WithType<false> { };
43
44 struct NotEmptyButTrue : Empty<false>, WithType<true> { };
45 struct NotEmptyAndFalse : Empty<false>, WithType<false> { };
46
47 template<typename Base>
48 constexpr bool test()
49 {
50 using traits = std::allocator_traits<Alloc<int, Base>>;
51 using test_type = typename traits::is_always_equal;
52 static_assert(std::is_base_of<std::true_type, test_type>::value
53 || std::is_base_of<std::false_type, test_type>::value,
54 "has correct base characteristic");
55 return test_type::value;
56 }
57
58 static_assert( test<Empty<true>>(), "empty type is always equal" );
59 static_assert( !test<Empty<false>>(), "non-empty type is not always equal" );
60
61 static_assert( test<EmptyAndTrue>(), "nested type is used" );
62 static_assert( !test<EmptyButFalse>(), "nested type is used" );
63
64 static_assert( test<NotEmptyButTrue>(), "nested type is used" );
65 static_assert( !test<NotEmptyAndFalse>(), "nested type is used" );