ebo_functor_holder.hpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Joaquin M Lopez Munoz 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_DETAIL_EBO_HOLDER_HPP
  13. #define BOOST_INTRUSIVE_DETAIL_EBO_HOLDER_HPP
  14. #include <boost/intrusive/detail/config_begin.hpp>
  15. #include <boost/intrusive/detail/mpl.hpp>
  16. namespace boost {
  17. namespace intrusive {
  18. namespace detail {
  19. template<typename T, bool IsEmpty = true>
  20. class ebo_functor_holder_impl
  21. {
  22. public:
  23. ebo_functor_holder_impl()
  24. {}
  25. ebo_functor_holder_impl(const T& t)
  26. : t_(t)
  27. {}
  28. template<class Arg1, class Arg2>
  29. ebo_functor_holder_impl(const Arg1& arg1, const Arg2& arg2)
  30. : t_(arg1, arg2)
  31. {}
  32. T& get(){return t_;}
  33. const T& get()const{return t_;}
  34. private:
  35. T t_;
  36. };
  37. template<typename T>
  38. class ebo_functor_holder_impl<T, false>
  39. : public T
  40. {
  41. public:
  42. ebo_functor_holder_impl()
  43. {}
  44. ebo_functor_holder_impl(const T& t)
  45. : T(t)
  46. {}
  47. template<class Arg1, class Arg2>
  48. ebo_functor_holder_impl(const Arg1& arg1, const Arg2& arg2)
  49. : T(arg1, arg2)
  50. {}
  51. T& get(){return *this;}
  52. const T& get()const{return *this;}
  53. };
  54. template<typename T>
  55. class ebo_functor_holder
  56. : public ebo_functor_holder_impl<T, is_unary_or_binary_function<T>::value>
  57. {
  58. private:
  59. typedef ebo_functor_holder_impl<T, is_unary_or_binary_function<T>::value> super;
  60. public:
  61. ebo_functor_holder(){}
  62. ebo_functor_holder(const T& t)
  63. : super(t)
  64. {}
  65. template<class Arg1, class Arg2>
  66. ebo_functor_holder(const Arg1& arg1, const Arg2& arg2)
  67. : super(arg1, arg2)
  68. {}
  69. ebo_functor_holder& operator=(const ebo_functor_holder& x)
  70. {
  71. this->get()=x.get();
  72. return *this;
  73. }
  74. };
  75. } //namespace detail {
  76. } //namespace intrusive {
  77. } //namespace boost {
  78. #include <boost/intrusive/detail/config_end.hpp>
  79. #endif //#ifndef BOOST_INTRUSIVE_DETAIL_EBO_HOLDER_HPP