Removed ugly reinterpret_cast
authorkhizmax <libcds.dev@gmail.com>
Sat, 18 Jul 2015 13:31:22 +0000 (16:31 +0300)
committerkhizmax <libcds.dev@gmail.com>
Sat, 18 Jul 2015 13:31:22 +0000 (16:31 +0300)
cds/details/marked_ptr.h

index 62ea44e88d4277519cf281625e9aa8a34da9d6d4..01a8b1cbf474f45feefe4ddea0b82fbe71389051 100644 (file)
@@ -22,7 +22,7 @@ namespace cds {
         template <typename T, int Bitmask>
         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<uintptr_t>( 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