trivial_value_traits.hpp 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2006-2013
  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.
  10. //
  11. /////////////////////////////////////////////////////////////////////////////
  12. #ifndef BOOST_INTRUSIVE_TRIVIAL_VALUE_TRAITS_HPP
  13. #define BOOST_INTRUSIVE_TRIVIAL_VALUE_TRAITS_HPP
  14. #include <boost/intrusive/link_mode.hpp>
  15. #include <boost/intrusive/pointer_traits.hpp>
  16. namespace boost {
  17. namespace intrusive {
  18. //!This value traits template is used to create value traits
  19. //!from user defined node traits where value_traits::value_type and
  20. //!node_traits::node should be equal
  21. template<class NodeTraits, link_mode_type LinkMode = normal_link>
  22. struct trivial_value_traits
  23. {
  24. typedef NodeTraits node_traits;
  25. typedef typename node_traits::node_ptr node_ptr;
  26. typedef typename node_traits::const_node_ptr const_node_ptr;
  27. typedef typename node_traits::node value_type;
  28. typedef node_ptr pointer;
  29. typedef const_node_ptr const_pointer;
  30. static const link_mode_type link_mode = LinkMode;
  31. static node_ptr to_node_ptr (value_type &value)
  32. { return pointer_traits<node_ptr>::pointer_to(value); }
  33. static const_node_ptr to_node_ptr (const value_type &value)
  34. { return pointer_traits<const_node_ptr>::pointer_to(value); }
  35. static const pointer & to_value_ptr(const node_ptr &n) { return n; }
  36. static const const_pointer &to_value_ptr(const const_node_ptr &n) { return n; }
  37. };
  38. } //namespace intrusive
  39. } //namespace boost
  40. #endif //BOOST_INTRUSIVE_TRIVIAL_VALUE_TRAITS_HPP