Differential D47360 Diff 219818 test/std/utilities/utility/mem.res/mem.poly.allocator.class/mem.poly.allocator.mem/construct_pair.pass.cpp
Changeset View
Changeset View
Standalone View
Standalone View
test/std/utilities/utility/mem.res/mem.poly.allocator.class/mem.poly.allocator.mem/construct_pair.pass.cpp
- This file was added.
//===----------------------------------------------------------------------===// | |||||
// | |||||
// The LLVM Compiler Infrastructure | |||||
// | |||||
// This file is dual licensed under the MIT and the University of Illinois Open | |||||
// Source Licenses. See LICENSE.TXT for details. | |||||
// | |||||
//===----------------------------------------------------------------------===// | |||||
// UNSUPPORTED: c++98, c++03 | |||||
// <memory_resource> | |||||
// template <class T> class polymorphic_allocator | |||||
// template <class U1, class U2> | |||||
// void polymorphic_allocator<T>::construct(pair<U1, U2>*) | |||||
#include <memory_resource> | |||||
#include <type_traits> | |||||
#include <utility> | |||||
#include <tuple> | |||||
#include <cassert> | |||||
#include <cstdlib> | |||||
#include "uses_alloc_types.h" | |||||
namespace ex = std::pmr; | |||||
int constructed = 0; | |||||
struct default_constructible | |||||
{ | |||||
default_constructible() : x(42) { ++constructed; } | |||||
int x{0}; | |||||
}; | |||||
int main(int, char**) | |||||
{ | |||||
// pair<default_constructible, default_constructible> as T() | |||||
{ | |||||
typedef default_constructible T; | |||||
typedef std::pair<T, T> P; | |||||
typedef ex::polymorphic_allocator<void> A; | |||||
P * ptr = (P*)std::malloc(sizeof(P)); | |||||
A a; | |||||
a.construct(ptr); | |||||
assert(constructed == 2); | |||||
assert(ptr->first.x == 42); | |||||
assert(ptr->second.x == 42); | |||||
std::free(ptr); | |||||
} | |||||
return 0; | |||||
} |