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// REQUIRES: c++experimental
11// UNSUPPORTED: c++98, c++03
12
13// <experimental/memory_resource>
14
15// template <class T> class polymorphic_allocator
16
17// template <class U1, class U2>
18// void polymorphic_allocator<T>::construct(pair<U1, U2>*)
19
20#include <experimental/memory_resource>
21#include <type_traits>
22#include <utility>
23#include <tuple>
24#include <cassert>
25#include <cstdlib>
26#include "uses_alloc_types.hpp"
27
28namespace ex = std::experimental::pmr;
29
30int constructed = 0;
31
32struct default_constructible
33{
34    default_constructible() : x(42)  { ++constructed; }
35    int x{0};
36};
37
38int main()
39{
40    // pair<default_constructible, default_constructible> as T()
41    {
42        typedef default_constructible T;
43        typedef std::pair<T, T> P;
44        typedef ex::polymorphic_allocator<void> A;
45        P * ptr = (P*)std::malloc(sizeof(P));
46        A a;
47        a.construct(ptr);
48        assert(constructed == 2);
49        assert(ptr->first.x == 42);
50        assert(ptr->second.x == 42);
51        std::free(ptr);
52    }
53}
54