Skip to content

Commit 3f9dc88

Browse files
committed
Added bx::addressOf.
1 parent f939b2c commit 3f9dc88

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

include/bx/bx.h

+4
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,10 @@ namespace bx
3838
template<class Ty>
3939
constexpr bool isTriviallyCopyable();
4040

41+
/// Find the address of an object of a class that has an overloaded unary ampersand (&) operator.
42+
template <class Ty>
43+
Ty* addressOf(Ty& _a);
44+
4145
/// Swap two values.
4246
template<typename Ty>
4347
void swap(Ty& _a, Ty& _b);

include/bx/inline/bx.inl

+10
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,16 @@ namespace bx
3333
return __is_trivially_copyable(Ty);
3434
}
3535

36+
template<class Ty>
37+
inline Ty* addressOf(Ty& _a)
38+
{
39+
return reinterpret_cast<Ty*>(
40+
&const_cast<char&>(
41+
reinterpret_cast<const volatile char&>(_a)
42+
)
43+
);
44+
}
45+
3646
template<typename Ty>
3747
inline void swap(Ty& _a, Ty& _b)
3848
{

0 commit comments

Comments
 (0)