Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r51452 - sandbox/mirror/boost/mirror/detail
From: chochlik_at_[hidden]
Date: 2009-02-26 10:32:03


Author: matus.chochlik
Date: 2009-02-26 10:32:02 EST (Thu, 26 Feb 2009)
New Revision: 51452
URL: http://svn.boost.org/trac/boost/changeset/51452

Log:
[mirror 0.3.x]
- minor bugfix of offset_of

Text files modified:
   sandbox/mirror/boost/mirror/detail/meta_attribs_base.hpp | 36 ++++++++++++++++++++++++++++++++----
   1 files changed, 32 insertions(+), 4 deletions(-)

Modified: sandbox/mirror/boost/mirror/detail/meta_attribs_base.hpp
==============================================================================
--- sandbox/mirror/boost/mirror/detail/meta_attribs_base.hpp (original)
+++ sandbox/mirror/boost/mirror/detail/meta_attribs_base.hpp 2009-02-26 10:32:02 EST (Thu, 26 Feb 2009)
@@ -23,6 +23,7 @@
 // necessary type traits
 #include <boost/call_traits.hpp>
 #include <boost/type_traits/is_pod.hpp>
+#include <boost/type_traits/alignment_of.hpp>
 // enable if
 #include <boost/utility/enable_if.hpp>
 //
@@ -555,6 +556,34 @@
         typedef unsigned char byte;
         typedef const byte* byte_ptr;
 
+ template <class T>
+ struct dummy_instance
+ {
+ inline T* ptr(void) const
+ {
+ return reinterpret_cast<T*>(
+ ::boost::alignment_of<T>::value
+ );
+ }
+
+ inline operator T& (void) const
+ {
+ T* pointer(ptr());
+ return *pointer;
+ }
+
+ inline operator const T& (void) const
+ {
+ const T* pointer(ptr());
+ return *pointer;
+ }
+
+ inline T* operator & (void) const
+ {
+ return ptr();
+ }
+ };
+
         static inline ptrdiff_t invalid_offset(void)
         {
                 return -1;
@@ -598,7 +627,7 @@
                 // this can be a problem with pod-types
                 // meta-types of which have custom implementation
                 // of address(...) expecting a valid instance
- T* pointer(0);
+ dummy_instance<T> instance;
                 //
                 // otherwise something like the following will
                 // be necessary:
@@ -607,7 +636,7 @@
                 //T* pointer((T*)alloc.allocate(1));
                 // ...
                 // alloc.deallocate(pointer, 1);
- return offset(*pointer, pos);
+ return offset(instance, pos);
         }
 
         template <class T, int I>
@@ -668,8 +697,7 @@
         template <int I>
         static inline ptrdiff_t offset_of(mpl::int_<I> pos)
         {
- Class* ptr(0);
- return get_offset_of(pos, ptr);
+ return get_offset_of(pos, (Class*)0);
         }
 };
 


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk