From: khizmax Date: Sat, 18 Jul 2015 13:31:22 +0000 (+0300) Subject: Removed ugly reinterpret_cast X-Git-Tag: v2.1.0~182 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=0f46a60b363a2c3a7bf45149f7cacbda74b7c574;p=libcds.git Removed ugly reinterpret_cast --- diff --git a/cds/details/marked_ptr.h b/cds/details/marked_ptr.h index 62ea44e8..01a8b1cb 100644 --- a/cds/details/marked_ptr.h +++ b/cds/details/marked_ptr.h @@ -22,7 +22,7 @@ namespace cds { template class marked_ptr { - T * m_ptr ; ///< pointer and its mark bits + T * m_ptr ; ///< pointer and its mark bits public: typedef T value_type ; ///< type of value the class points to @@ -67,14 +67,21 @@ namespace cds { private: //@cond + union pointer_cast { + T * ptr; + uintptr_t n; + + pointer_cast(T * p) : ptr(p) {} + pointer_cast(uintptr_t i) : n(i) {} + }; static uintptr_t to_int( value_type * p ) CDS_NOEXCEPT { - return reinterpret_cast( p ); + return pointer_cast(p).n; } static value_type * to_ptr( uintptr_t n ) CDS_NOEXCEPT { - return reinterpret_cast< value_type *>( n ); + return pointer_cast(n).ptr; } uintptr_t to_int() const CDS_NOEXCEPT