1 /////////////////////////////////////////////////////////////////////////////
3 // (C) Copyright Ion Gaztanaga 2014-2014
5 // Distributed under the Boost Software License, Version 1.0.
6 // (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
9 // See http://www.boost.org/libs/intrusive for documentation.
11 /////////////////////////////////////////////////////////////////////////////
13 #ifndef BOOST_INTRUSIVE_DETAIL_DEFAULT_HEADER_HOLDER_HPP
14 #define BOOST_INTRUSIVE_DETAIL_DEFAULT_HEADER_HOLDER_HPP
16 #ifndef BOOST_CONFIG_HPP
17 # include <boost/config.hpp>
20 #if defined(BOOST_HAS_PRAGMA_ONCE)
24 #include <boost/intrusive/detail/workaround.hpp>
25 #include <boost/intrusive/pointer_traits.hpp>
26 #include <boost/intrusive/detail/to_raw_pointer.hpp>
32 // trivial header node holder
33 template < typename NodeTraits >
34 struct default_header_holder : public NodeTraits::node
36 typedef NodeTraits node_traits;
37 typedef typename node_traits::node node;
38 typedef typename node_traits::node_ptr node_ptr;
39 typedef typename node_traits::const_node_ptr const_node_ptr;
41 default_header_holder() : node() {}
43 BOOST_INTRUSIVE_FORCEINLINE const_node_ptr get_node() const
44 { return pointer_traits< const_node_ptr >::pointer_to(*static_cast< const node* >(this)); }
46 BOOST_INTRUSIVE_FORCEINLINE node_ptr get_node()
47 { return pointer_traits< node_ptr >::pointer_to(*static_cast< node* >(this)); }
49 // (unsafe) downcast used to implement container-from-iterator
50 BOOST_INTRUSIVE_FORCEINLINE static default_header_holder* get_holder(const node_ptr &p)
51 { return static_cast< default_header_holder* >(boost::intrusive::detail::to_raw_pointer(p)); }
54 // type function producing the header node holder
55 template < typename ValueTraits, typename HeaderHolder >
56 struct get_header_holder_type
58 typedef HeaderHolder type;
60 template < typename ValueTraits >
61 struct get_header_holder_type< ValueTraits, void >
63 typedef default_header_holder< typename ValueTraits::node_traits > type;
67 } //namespace intrusive
70 #endif //BOOST_INTRUSIVE_DETAIL_DEFAULT_HEADER_HOLDER_HPP