blob: 446daa1ec9f2a5c9d09eb4ef28d4cdd6349337e8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// Make sure that std::allocate_shared works with an allocator type that is
// only explicitly convertible from another specialization of itself.
#include <cassert>
#include <cstddef>
#include <memory>
template <class T>
struct ExplicitAllocator {
ExplicitAllocator() = default;
template <class U>
explicit ExplicitAllocator(ExplicitAllocator<U>) { }
using value_type = T;
T* allocate(std::size_t n) { return std::allocator<T>().allocate(n); }
void deallocate(T* ptr, std::size_t n) { return std::allocator<T>().deallocate(ptr, n); }
};
int main(int, char**) {
std::shared_ptr<int> ptr = std::allocate_shared<int>(ExplicitAllocator<int>(), 0);
(void)ptr;
return 0;
}
|