fix doc example typo
[boost.git] / boost / intrusive / member_value_traits.hpp
blob372334c95899273925ae732eb79df4a9188ad711
1 /////////////////////////////////////////////////////////////////////////////
2 //
3 // (C) Copyright Ion Gaztanaga 2006-2008
4 //
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)
8 //
9 // See http://www.boost.org/libs/intrusive for documentation.
11 /////////////////////////////////////////////////////////////////////////////
13 #ifndef BOOST_INTRUSIVE_MEMBER_VALUE_TRAITS_HPP
14 #define BOOST_INTRUSIVE_MEMBER_VALUE_TRAITS_HPP
16 #include <boost/intrusive/link_mode.hpp>
17 #include <iterator>
18 #include <boost/intrusive/detail/parent_from_member.hpp>
20 namespace boost {
21 namespace intrusive {
23 //!This value traits template is used to create value traits
24 //!from user defined node traits where value_traits::value_type will
25 //!store a node_traits::node
26 template< class T, class NodeTraits
27 , typename NodeTraits::node T::* PtrToMember
28 , link_mode_type LinkMode = safe_link>
29 struct member_value_traits
31 public:
32 typedef NodeTraits node_traits;
33 typedef T value_type;
34 typedef typename node_traits::node node;
35 typedef typename node_traits::node_ptr node_ptr;
36 typedef typename node_traits::const_node_ptr const_node_ptr;
37 typedef typename boost::pointer_to_other<node_ptr, T>::type pointer;
38 typedef typename boost::pointer_to_other<node_ptr, const T>::type const_pointer;
39 typedef typename std::iterator_traits<pointer>::reference reference;
40 typedef typename std::iterator_traits<const_pointer>::reference const_reference;
41 static const link_mode_type link_mode = LinkMode;
43 static node_ptr to_node_ptr(reference value)
44 { return node_ptr(&(value.*PtrToMember)); }
46 static const_node_ptr to_node_ptr(const_reference value)
47 { return node_ptr(&(value.*PtrToMember)); }
49 static pointer to_value_ptr(node_ptr n)
51 return pointer(detail::parent_from_member<value_type, node>
52 (detail::get_pointer(n), PtrToMember));
55 static const_pointer to_value_ptr(const_node_ptr n)
57 return pointer(detail::parent_from_member<value_type, node>
58 (detail::get_pointer(n), PtrToMember));
62 } //namespace intrusive
63 } //namespace boost
65 #endif //BOOST_INTRUSIVE_MEMBER_VALUE_TRAITS_HPP