///////////////////////////////////////////////////////////////////////////// // // (C) Copyright Gordon Woodhull 2008 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // This is a contribution to Boost.Intrusive to support hooks as // elements in Boost.Fusion containers // ///////////////////////////////////////////////////////////////////////////// #ifndef BOOST_INTRUSIVE_PARENT_FROM_MEMBER_HPP #define BOOST_INTRUSIVE_PARENT_FROM_MEMBER_HPP #include #include #include #include #include #include #include #include #include "vector_pointer_to_member.hpp" namespace boost { namespace intrusive { namespace detail { // this would be better a metafunction but that would mean converting parent_from_member first template inline std::size_t offset_from_fusion_map_to_element() { // this attempts to use the offset of the element in the fusion::vector implementation of fusion::map // which would work if a class with one member has the same address as its member // however, probably a bad assumption and would need a sequence of pointers-to-members // also this should be metafunction typedef typename fusion::result_of::template find::type found_iter; // this line causes gcc bus error?? //typedef typename fusion::template end::type end_type //BOOST_MPL_ASSERT_NOT((is_same)); // this does not compile because vector_ptr_to_member only works with fusion::vector##<> not fusion::vector<> typename fusish::template vector_ptr_to_member_type::type p2m = fusish::vector_ptr_to_member(); return boost::intrusive::detail::offset_from_pointer_to_member(p2m); } template inline FusionMap *fusion_map_from_element(Element *element) { return (FusionMap*)((char*)element - offset_from_fusion_map_to_element()); } template inline const FusionMap *fusion_map_from_element(const Element *element) { return (const FusionMap*)((const char*)element - offset_from_fusion_map_to_element()); } } //namespace detail { } //namespace intrusive { } //namespace boost { #include #endif //#ifndef BOOST_INTRUSIVE_PARENT_FROM_MEMBER_HPP