From 723d4d3fe6884f9a5057f2057c2a9a6dbc1e3f9a Mon Sep 17 00:00:00 2001 From: Yedidya Feldblum Date: Thu, 2 Nov 2017 09:55:29 -0700 Subject: [PATCH] Refactor is_simple_allocator and callers Summary: [Folly] Refactor `is_simple_allocator` and callers. * Swap order of template parameters. * Do decaying in the callers instead. * Do a direct invocability test, rather than an indirect test of whether the allocator has a method `destroy` with the expected signature. Reviewed By: ericniebler Differential Revision: D6184062 fbshipit-source-id: aec32e6e323b8c6023b94c258ab2bcddd8c53e09 --- folly/Memory.h | 41 +++++++++++++++++++------------- folly/test/ArenaSmartPtrTest.cpp | 2 +- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/folly/Memory.h b/folly/Memory.h index 446d8896..ce0ff05d 100644 --- a/folly/Memory.h +++ b/folly/Memory.h @@ -17,6 +17,7 @@ #pragma once #include +#include #include #include @@ -24,6 +25,7 @@ #include #include #include +#include #include namespace folly { @@ -344,25 +346,23 @@ class allocator_delete } }; -template -class is_simple_allocator { - FOLLY_CREATE_HAS_MEMBER_FN_TRAITS(has_destroy, destroy); +namespace detail { - typedef typename std::remove_const< - typename std::remove_reference::type - >::type allocator; - typedef typename std::remove_reference::type value_type; - typedef value_type* pointer; +FOLLY_CREATE_MEMBER_INVOKE_TRAITS(destroy_invoke_traits, destroy); - public: - constexpr static bool value = !has_destroy::value - && !has_destroy::value; -}; +} // namespace detail + +template +using is_simple_allocator = + Negation>; template struct as_stl_allocator { typedef typename std::conditional< - is_simple_allocator::value, + is_simple_allocator< + typename std::remove_reference::type, + typename std::remove_reference::type + >::value, folly::StlAllocator< typename std::remove_reference::type, typename std::remove_reference::type @@ -373,7 +373,10 @@ struct as_stl_allocator { template typename std::enable_if< - is_simple_allocator::value, + is_simple_allocator< + typename std::remove_reference::type, + typename std::remove_reference::type + >::value, folly::StlAllocator< typename std::remove_reference::type, typename std::remove_reference::type @@ -387,7 +390,10 @@ typename std::enable_if< template typename std::enable_if< - !is_simple_allocator::value, + !is_simple_allocator< + typename std::remove_reference::type, + typename std::remove_reference::type + >::value, typename std::remove_reference::type >::type make_stl_allocator(Allocator&& allocator) { return std::move(allocator); @@ -405,7 +411,10 @@ struct AllocatorUniquePtr { typedef std::unique_ptr::value, + is_simple_allocator< + typename std::remove_reference::type, + typename std::remove_reference::type + >::value, folly::StlAllocator::type, T>, typename std::remove_reference::type >::type diff --git a/folly/test/ArenaSmartPtrTest.cpp b/folly/test/ArenaSmartPtrTest.cpp index ee94db0e..bad1af5a 100644 --- a/folly/test/ArenaSmartPtrTest.cpp +++ b/folly/test/ArenaSmartPtrTest.cpp @@ -25,7 +25,7 @@ using namespace folly; static_assert( - is_simple_allocator::value, + is_simple_allocator::value, "SysArena should be a simple allocator" ); -- 2.34.1