common_functors.hpp 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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_TEST_COMMON_FUNCTORS_HPP
  13. #define BOOST_INTRUSIVE_TEST_COMMON_FUNCTORS_HPP
  14. #include<boost/intrusive/detail/iterator.hpp>
  15. #include<boost/intrusive/detail/mpl.hpp>
  16. #include<boost/static_assert.hpp>
  17. #include<boost/move/detail/to_raw_pointer.hpp>
  18. namespace boost {
  19. namespace intrusive {
  20. namespace test {
  21. template<class T>
  22. class delete_disposer
  23. {
  24. public:
  25. template <class Pointer>
  26. void operator()(Pointer p)
  27. {
  28. typedef typename boost::intrusive::iterator_traits<Pointer>::value_type value_type;
  29. BOOST_STATIC_ASSERT(( detail::is_same<T, value_type>::value ));
  30. delete boost::movelib::to_raw_pointer(p);
  31. }
  32. };
  33. template<class T>
  34. class new_cloner
  35. {
  36. public:
  37. T *operator()(const T &t)
  38. { return new T(t); }
  39. };
  40. template<class T>
  41. class new_nonconst_cloner
  42. {
  43. public:
  44. T *operator()(T &t)
  45. { return new T(t); }
  46. };
  47. template<class T>
  48. class new_default_factory
  49. {
  50. public:
  51. T *operator()()
  52. { return new T(); }
  53. };
  54. class empty_disposer
  55. {
  56. public:
  57. template<class T>
  58. void operator()(const T &)
  59. {}
  60. };
  61. struct any_less
  62. {
  63. template<class T, class U>
  64. bool operator()(const T &t, const U &u) const
  65. { return t < u; }
  66. };
  67. struct any_greater
  68. {
  69. template<class T, class U>
  70. bool operator()(const T &t, const U &u) const
  71. { return t > u; }
  72. };
  73. } //namespace test {
  74. } //namespace intrusive {
  75. } //namespace boost {
  76. #endif