diff --git a/folly/lang/Thunk.h b/folly/lang/Thunk.h index dd697b1ba08..3d902da3827 100644 --- a/folly/lang/Thunk.h +++ b/folly/lang/Thunk.h @@ -19,6 +19,7 @@ #include #include +#include namespace folly { namespace detail { @@ -73,6 +74,19 @@ struct thunk { return ::new (dst) T(static_cast(*reinterpret_cast(src))); } + template + static void* operator_new() { + return folly::operator_new(Size, align_val_t(Align)); + } + template + static void* operator_new_nx() { + return folly::operator_new(Size, align_val_t(Align), std::nothrow); + } + template + static void operator_delete(void* const ptr) noexcept { + return folly::operator_delete(ptr, Size, align_val_t(Align)); + } + template static void noop(A...) noexcept {} diff --git a/folly/lang/test/ThunkTest.cpp b/folly/lang/test/ThunkTest.cpp index d8170acba34..4e5a223bd0f 100644 --- a/folly/lang/test/ThunkTest.cpp +++ b/folly/lang/test/ThunkTest.cpp @@ -93,4 +93,13 @@ TEST_F(ThunkTest, ctor_dtor) { } } +TEST_F(ThunkTest, operator_new_delete) { + auto ptr = thunk::operator_new<64, 32>(); + EXPECT_NE(nullptr, ptr); + thunk::operator_delete<64, 32>(ptr); + ptr = thunk::operator_new_nx<64, 32>(); + EXPECT_NE(nullptr, ptr); + thunk::operator_delete<64, 32>(ptr); +} + } // namespace folly::detail