]>
Commit | Line | Data |
---|---|---|
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 | ||
24 | template<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 | ||
35 | template<bool> struct Empty { }; | |
36 | template<> struct Empty<false> { int x; }; | |
37 | ||
38 | template<bool B> | |
39 | struct WithType | |
40 | { using is_always_equal = std::integral_constant<bool, B>; }; | |
41 | ||
42 | struct EmptyAndTrue : Empty<true>, WithType<true> { }; | |
43 | struct EmptyButFalse : Empty<true>, WithType<false> { }; | |
44 | ||
45 | struct NotEmptyButTrue : Empty<false>, WithType<true> { }; | |
46 | struct NotEmptyAndFalse : Empty<false>, WithType<false> { }; | |
47 | ||
48 | template<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 | ||
59 | static_assert( test<Empty<true>>(), "empty type is always equal" ); | |
60 | static_assert( !test<Empty<false>>(), "non-empty type is not always equal" ); | |
61 | ||
62 | static_assert( test<EmptyAndTrue>(), "nested type is used" ); | |
63 | static_assert( !test<EmptyButFalse>(), "nested type is used" ); | |
64 | ||
65 | static_assert( test<NotEmptyButTrue>(), "nested type is used" ); | |
66 | static_assert( !test<NotEmptyAndFalse>(), "nested type is used" ); |