]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/allocator_traits/members/is_always_equal.cc
1 // Copyright (C) 2015-2020 Free Software Foundation, Inc.
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)
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.
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/>.
18 // { dg-do compile { target c++11 } }
20 #include <type_traits>
23 template<typename T
, typename Base
>
29 Alloc(const Alloc
<U
, Base
>&);
30 T
* allocate(std::size_t);
31 void deallocate(T
*, std::size_t);
34 template<bool> struct Empty
{ };
35 template<> struct Empty
<false> { int x
; };
39 { using is_always_equal
= std::integral_constant
<bool, B
>; };
41 struct EmptyAndTrue
: Empty
<true>, WithType
<true> { };
42 struct EmptyButFalse
: Empty
<true>, WithType
<false> { };
44 struct NotEmptyButTrue
: Empty
<false>, WithType
<true> { };
45 struct NotEmptyAndFalse
: Empty
<false>, WithType
<false> { };
47 template<typename Base
>
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
;
58 static_assert( test
<Empty
<true>>(), "empty type is always equal" );
59 static_assert( !test
<Empty
<false>>(), "non-empty type is not always equal" );
61 static_assert( test
<EmptyAndTrue
>(), "nested type is used" );
62 static_assert( !test
<EmptyButFalse
>(), "nested type is used" );
64 static_assert( test
<NotEmptyButTrue
>(), "nested type is used" );
65 static_assert( !test
<NotEmptyAndFalse
>(), "nested type is used" );