Бранимир Караџић 4 лет назад
Родитель
Сommit
3f9dc88e64
2 измененных файлов с 14 добавлено и 0 удалено
  1. 4 0
      include/bx/bx.h
  2. 10 0
      include/bx/inline/bx.inl

+ 4 - 0
include/bx/bx.h

@@ -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);

+ 10 - 0
include/bx/inline/bx.inl

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