Eric Fiselier | 257fd69 | 2016-05-07 01:04:55 +0000 | [diff] [blame] | 1 | //===----------------------------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is dual licensed under the MIT and the University of Illinois Open |
| 6 | // Source Licenses. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
| 10 | // UNSUPPORTED: c++98, c++03 |
| 11 | |
| 12 | // <experimental/memory_resource> |
| 13 | |
| 14 | // template <class T> class polymorphic_allocator |
| 15 | |
| 16 | // template <class U1, class U2> |
| 17 | // void polymorphic_allocator<T>::construct(pair<U1, U2>*) |
| 18 | |
| 19 | #include <experimental/memory_resource> |
| 20 | #include <type_traits> |
| 21 | #include <utility> |
| 22 | #include <tuple> |
| 23 | #include <cassert> |
| 24 | #include <cstdlib> |
| 25 | #include "uses_alloc_types.hpp" |
| 26 | |
| 27 | namespace ex = std::experimental::pmr; |
| 28 | |
| 29 | int constructed = 0; |
| 30 | |
| 31 | struct default_constructible |
| 32 | { |
| 33 | default_constructible() : x(42) { ++constructed; } |
| 34 | int x{0}; |
| 35 | }; |
| 36 | |
| 37 | int main() |
| 38 | { |
| 39 | // pair<default_constructible, default_constructible> as T() |
| 40 | { |
| 41 | typedef default_constructible T; |
| 42 | typedef std::pair<T, T> P; |
| 43 | typedef ex::polymorphic_allocator<void> A; |
| 44 | P * ptr = (P*)std::malloc(sizeof(P)); |
| 45 | A a; |
| 46 | a.construct(ptr); |
| 47 | assert(constructed == 2); |
| 48 | assert(ptr->first.x == 42); |
| 49 | assert(ptr->second.x == 42); |
| 50 | std::free(ptr); |
| 51 | } |
| 52 | } |