From 3f9dc88e64b34db414839efe86edd6915a3e0547 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=91=D1=80=D0=B0=D0=BD=D0=B8=D0=BC=D0=B8=D1=80=20=D0=9A?= =?UTF-8?q?=D0=B0=D1=80=D0=B0=D1=9F=D0=B8=D1=9B?= Date: Mon, 5 Apr 2021 12:27:31 -0700 Subject: [PATCH] Added bx::addressOf. --- include/bx/bx.h | 4 ++++ include/bx/inline/bx.inl | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/include/bx/bx.h b/include/bx/bx.h index ff6e8d9..36f40aa 100644 --- a/include/bx/bx.h +++ b/include/bx/bx.h @@ -38,6 +38,10 @@ namespace bx template constexpr bool isTriviallyCopyable(); + /// Find the address of an object of a class that has an overloaded unary ampersand (&) operator. + template + Ty* addressOf(Ty& _a); + /// Swap two values. template void swap(Ty& _a, Ty& _b); diff --git a/include/bx/inline/bx.inl b/include/bx/inline/bx.inl index 41b527b..fc527ec 100644 --- a/include/bx/inline/bx.inl +++ b/include/bx/inline/bx.inl @@ -33,6 +33,16 @@ namespace bx return __is_trivially_copyable(Ty); } + template + inline Ty* addressOf(Ty& _a) + { + return reinterpret_cast( + &const_cast( + reinterpret_cast(_a) + ) + ); + } + template inline void swap(Ty& _a, Ty& _b) {