| 1 | // Copyright (C) 2016-2025 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 <scoped_allocator> |
| 21 | #include <testsuite_allocator.h> |
| 22 | |
| 23 | template<typename T> |
| 24 | struct alloc |
| 25 | { |
| 26 | using value_type = T; |
| 27 | alloc() = default; |
| 28 | template<typename U> |
| 29 | alloc(alloc<U>) { } |
| 30 | T* allocate(std::size_t); |
| 31 | void deallocate(T*, std::size_t); |
| 32 | }; |
| 33 | |
| 34 | template<typename T, typename U> |
| 35 | bool operator==(alloc<T>, alloc<U>) { return true; } |
| 36 | |
| 37 | template<typename T, typename U> |
| 38 | bool operator!=(alloc<T>, alloc<U>) { return false; } |
| 39 | |
| 40 | using scoped = std::scoped_allocator_adaptor<alloc<int>>; |
| 41 | using other_alloc = __gnu_test::SimpleAllocator<int>; |
| 42 | using other_scoped = std::scoped_allocator_adaptor<other_alloc>; |
| 43 | |
| 44 | using std::is_constructible; |
| 45 | |
| 46 | static_assert( is_constructible<scoped, const scoped&>::value, |
| 47 | "is_constructible<scoped, const scoped&>"); |
| 48 | static_assert( is_constructible<scoped, scoped>::value, |
| 49 | "is_constructible<scoped, scoped>"); |
| 50 | static_assert( is_constructible<scoped, const alloc<int>&>::value, |
| 51 | "is_constructible<scoped, const outer_allocator_type&>"); |
| 52 | static_assert( is_constructible<scoped, alloc<int>>::value, |
| 53 | "is_constructible<scoped, outer_allocator_type>"); |
| 54 | static_assert( is_constructible<scoped, const alloc<long>&>::value, |
| 55 | "is_constructible<scoped, const outer_allocator_type::rebind<U>::type&>"); |
| 56 | static_assert( is_constructible<scoped, alloc<long>>::value, |
| 57 | "is_constructible<scoped, outer_allocator_type::rebind<U>::type>"); |
| 58 | |
| 59 | static_assert( !is_constructible<scoped, const other_alloc&>::value, |
| 60 | "!is_constructible<scoped, const other_alloc&>"); |
| 61 | static_assert( !is_constructible<scoped, other_alloc>::value, |
| 62 | "!is_constructible<scoped, other_alloc>"); |
| 63 | static_assert( !is_constructible<scoped, const other_scoped&>::value, |
| 64 | "!is_constructible<scoped, const other_scoped&>"); |
| 65 | static_assert( !is_constructible<scoped, other_scoped>::value, |
| 66 | "!is_constructible<scoped, other_scoped>"); |