]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/20_util/allocator_traits/members/is_always_equal.cc
1 // Copyright (C) 2015-2016 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-options "-std=gnu++11" }
21 #include <type_traits>
24 template<typename T
, typename Base
>
30 Alloc(const Alloc
<U
, Base
>&);
31 T
* allocate(std::size_t);
32 void deallocate(T
*, std::size_t);
35 template<bool> struct Empty
{ };
36 template<> struct Empty
<false> { int x
; };
40 { using is_always_equal
= std::integral_constant
<bool, B
>; };
42 struct EmptyAndTrue
: Empty
<true>, WithType
<true> { };
43 struct EmptyButFalse
: Empty
<true>, WithType
<false> { };
45 struct NotEmptyButTrue
: Empty
<false>, WithType
<true> { };
46 struct NotEmptyAndFalse
: Empty
<false>, WithType
<false> { };
48 template<typename Base
>
51 using traits
= std::allocator_traits
<Alloc
<int, Base
>>;
52 using test_type
= typename
traits::is_always_equal
;
53 static_assert(std::is_base_of
<std::true_type
, test_type
>::value
54 || std::is_base_of
<std::false_type
, test_type
>::value
,
55 "has correct base characteristic");
56 return test_type::value
;
59 static_assert( test
<Empty
<true>>(), "empty type is always equal" );
60 static_assert( !test
<Empty
<false>>(), "non-empty type is not always equal" );
62 static_assert( test
<EmptyAndTrue
>(), "nested type is used" );
63 static_assert( !test
<EmptyButFalse
>(), "nested type is used" );
65 static_assert( test
<NotEmptyButTrue
>(), "nested type is used" );
66 static_assert( !test
<NotEmptyAndFalse
>(), "nested type is used" );