blob: 9ce04045058e4dc0742b5aecc480baafb3fdfb2c [file] [log] [blame]
Eric Fiselier257fd692016-05-07 01:04:55 +00001//===----------------------------------------------------------------------===//
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
27namespace ex = std::experimental::pmr;
28
29int constructed = 0;
30
31struct default_constructible
32{
33 default_constructible() : x(42) { ++constructed; }
34 int x{0};
35};
36
37int 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}