Commit 5ee564ba authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Adjust allocator ctors

Summary:
[Folly] Adjust allocator ctors.

* Add missing family ctor to `SysAllocator` to bring it into better alignment with generic C++ allocator expectations.
* Make other family ctors implicit.
* Ensure that the actual copy ctors take precedence.
* Hide copy assignment operators.

Reviewed By: marksantaniello

Differential Revision: D19817836

fbshipit-source-id: de90fdd7cae36ac178a89556e63a29f4014532a1
parent 552c07c3
...@@ -373,6 +373,13 @@ class SysAllocator { ...@@ -373,6 +373,13 @@ class SysAllocator {
public: public:
using value_type = T; using value_type = T;
constexpr SysAllocator() = default;
constexpr SysAllocator(SysAllocator const&) = default;
template <typename U, std::enable_if_t<!std::is_same<U, T>::value, int> = 0>
constexpr SysAllocator(SysAllocator<U> const&) noexcept {}
T* allocate(size_t count) { T* allocate(size_t count) {
using lifted = typename detail::lift_void_to_char<T>::type; using lifted = typename detail::lift_void_to_char<T>::type;
auto const p = std::malloc(sizeof(lifted) * count); auto const p = std::malloc(sizeof(lifted) * count);
...@@ -483,8 +490,10 @@ class AlignedSysAllocator : private Align { ...@@ -483,8 +490,10 @@ class AlignedSysAllocator : private Align {
std::enable_if_t<std::is_default_constructible<S>::value, int> = 0> std::enable_if_t<std::is_default_constructible<S>::value, int> = 0>
constexpr AlignedSysAllocator() noexcept(noexcept(Align())) : Align() {} constexpr AlignedSysAllocator() noexcept(noexcept(Align())) : Align() {}
template <typename U> constexpr AlignedSysAllocator(AlignedSysAllocator const&) = default;
constexpr explicit AlignedSysAllocator(
template <typename U, std::enable_if_t<!std::is_same<U, T>::value, int> = 0>
constexpr AlignedSysAllocator(
AlignedSysAllocator<U, Align> const& other) noexcept AlignedSysAllocator<U, Align> const& other) noexcept
: Align(other.align()) {} : Align(other.align()) {}
...@@ -540,10 +549,12 @@ class CxxAllocatorAdaptor { ...@@ -540,10 +549,12 @@ class CxxAllocatorAdaptor {
using propagate_on_container_move_assignment = std::true_type; using propagate_on_container_move_assignment = std::true_type;
using propagate_on_container_swap = std::true_type; using propagate_on_container_swap = std::true_type;
explicit CxxAllocatorAdaptor(Inner& ref) : ref_(ref) {} constexpr explicit CxxAllocatorAdaptor(Inner& ref) : ref_(ref) {}
template <typename U> constexpr CxxAllocatorAdaptor(CxxAllocatorAdaptor const&) = default;
explicit CxxAllocatorAdaptor(CxxAllocatorAdaptor<U, Inner> const& other)
template <typename U, std::enable_if_t<!std::is_same<U, T>::value, int> = 0>
constexpr CxxAllocatorAdaptor(CxxAllocatorAdaptor<U, Inner> const& other)
: ref_(other.ref_) {} : ref_(other.ref_) {}
T* allocate(std::size_t n) { T* allocate(std::size_t n) {
......
...@@ -158,7 +158,7 @@ class reentrant_allocator : private detail::reentrant_allocator_base { ...@@ -158,7 +158,7 @@ class reentrant_allocator : private detail::reentrant_allocator_base {
using base::base; using base::base;
template <typename U> template <typename U, std::enable_if_t<!std::is_same<U, T>::value, int> = 0>
/* implicit */ reentrant_allocator( /* implicit */ reentrant_allocator(
reentrant_allocator<U> const& that) noexcept reentrant_allocator<U> const& that) noexcept
: base{that} {} : base{that} {}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment