]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/testsuite/20_util/allocator_traits/members/is_always_equal.cc
Restore dg-interpreter-batch-mode for libstdc++ tests
[thirdparty/gcc.git] / libstdc++-v3 / testsuite / 20_util / allocator_traits / members / is_always_equal.cc
CommitLineData
818ab71a 1// Copyright (C) 2015-2016 Free Software Foundation, Inc.
a2b5fdcb
JW
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-options "-std=gnu++11" }
19// { dg-do compile }
20
21#include <type_traits>
22#include <memory>
23
24template<typename T, typename Base>
25 struct Alloc : Base
26 {
27 typedef T value_type;
28 Alloc();
29 template <typename U>
30 Alloc(const Alloc<U, Base>&);
31 T* allocate(std::size_t);
32 void deallocate(T*, std::size_t);
33 };
34
35template<bool> struct Empty { };
36template<> struct Empty<false> { int x; };
37
38template<bool B>
39 struct WithType
40 { using is_always_equal = std::integral_constant<bool, B>; };
41
42struct EmptyAndTrue : Empty<true>, WithType<true> { };
43struct EmptyButFalse : Empty<true>, WithType<false> { };
44
45struct NotEmptyButTrue : Empty<false>, WithType<true> { };
46struct NotEmptyAndFalse : Empty<false>, WithType<false> { };
47
48template<typename Base>
49 constexpr bool test()
50 {
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;
57 }
58
59static_assert( test<Empty<true>>(), "empty type is always equal" );
60static_assert( !test<Empty<false>>(), "non-empty type is not always equal" );
61
62static_assert( test<EmptyAndTrue>(), "nested type is used" );
63static_assert( !test<EmptyButFalse>(), "nested type is used" );
64
65static_assert( test<NotEmptyButTrue>(), "nested type is used" );
66static_assert( !test<NotEmptyAndFalse>(), "nested type is used" );