Commit 55dfcb03 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

let some thunk members take variadic args

Summary: In particular, let `make` and `ctor` take variadic arguments since there is no cost.

Reviewed By: iahs

Differential Revision: D27024839

fbshipit-source-id: 805c65fdc79f60af1256a4c36be94bb22c163bdd
parent 6329dbd5
...@@ -420,27 +420,27 @@ namespace detail { ...@@ -420,27 +420,27 @@ namespace detail {
// thunk // thunk
// //
// A carefully curated collection of generic general-purpose thunk templates: // A carefully curated collection of generic general-purpose thunk templates:
// * make: operator new with default constructor // * make: operator new with given arguments
// * ruin: operator delete // * ruin: operator delete
// * ctor: in-place default constructor // * ctor: in-place constructor with given arguments
// * dtor: in-place destructor // * dtor: in-place destructor
// * noop: no-op function with the given arguments // * noop: no-op function with the given arguments
struct thunk { struct thunk {
template <typename T> template <typename T, typename... A>
static void* make() { static void* make(A... a) {
return new T(); return new T(static_cast<A>(a)...);
} }
template <typename T> template <typename T>
static void ruin(void* ptr) noexcept { static void ruin(void* const ptr) noexcept {
delete static_cast<T*>(ptr); delete static_cast<T*>(ptr);
} }
template <typename T> template <typename T, typename... A>
static void ctor(void* ptr) { static void ctor(void* const ptr, A... a) {
::new (ptr) T(); ::new (ptr) T(static_cast<A>(a)...);
} }
template <typename T> template <typename T>
static void dtor(void* ptr) noexcept { static void dtor(void* const ptr) noexcept {
static_cast<T*>(ptr)->~T(); static_cast<T*>(ptr)->~T();
} }
......
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