Added bx::addressOf.

This commit is contained in:
Бранимир Караџић
2021-04-05 12:27:31 -07:00
parent f939b2c317
commit 3f9dc88e64
2 changed files with 14 additions and 0 deletions

View File

@@ -38,6 +38,10 @@ namespace bx
template<class Ty>
constexpr bool isTriviallyCopyable();
/// Find the address of an object of a class that has an overloaded unary ampersand (&) operator.
template <class Ty>
Ty* addressOf(Ty& _a);
/// Swap two values.
template<typename Ty>
void swap(Ty& _a, Ty& _b);

View File

@@ -33,6 +33,16 @@ namespace bx
return __is_trivially_copyable(Ty);
}
template<class Ty>
inline Ty* addressOf(Ty& _a)
{
return reinterpret_cast<Ty*>(
&const_cast<char&>(
reinterpret_cast<const volatile char&>(_a)
)
);
}
template<typename Ty>
inline void swap(Ty& _a, Ty& _b)
{