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) {