preprocessor.hpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // (C) Copyright Ion Gaztanaga 2008-2012. Distributed under the Boost
  4. // Software License, Version 1.0. (See accompanying file
  5. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. //
  7. // See http://www.boost.org/libs/interprocess for documentation.
  8. //
  9. //////////////////////////////////////////////////////////////////////////////
  10. #ifndef BOOST_INTERPROCESS_DETAIL_PREPROCESSOR_HPP
  11. #define BOOST_INTERPROCESS_DETAIL_PREPROCESSOR_HPP
  12. #if (defined _MSC_VER) && (_MSC_VER >= 1200)
  13. # pragma once
  14. #endif
  15. #include <boost/interprocess/detail/config_begin.hpp>
  16. #ifdef BOOST_INTERPROCESS_PERFECT_FORWARDING
  17. #error "This file is not needed when perfect forwarding is available"
  18. #endif
  19. #include <boost/preprocessor/iteration/local.hpp>
  20. #include <boost/preprocessor/repetition/enum_params.hpp>
  21. #include <boost/preprocessor/cat.hpp>
  22. #include <boost/preprocessor/repetition/enum.hpp>
  23. #include <boost/preprocessor/repetition/repeat.hpp>
  24. #define BOOST_INTERPROCESS_MAX_CONSTRUCTOR_PARAMETERS 10
  25. //Note:
  26. //We define template parameters as const references to
  27. //be able to bind temporaries. After that we will un-const them.
  28. //This cast is ugly but it is necessary until "perfect forwarding"
  29. //is achieved in C++0x. Meanwhile, if we want to be able to
  30. //bind rvalues with non-const references, we have to be ugly
  31. #ifndef BOOST_NO_RVALUE_REFERENCES
  32. #define BOOST_INTERPROCESS_PP_PARAM_LIST(z, n, data) \
  33. BOOST_PP_CAT(P, n) && BOOST_PP_CAT(p, n) \
  34. //!
  35. #else
  36. #define BOOST_INTERPROCESS_PP_PARAM_LIST(z, n, data) \
  37. const BOOST_PP_CAT(P, n) & BOOST_PP_CAT(p, n) \
  38. //!
  39. #endif
  40. #ifndef BOOST_NO_RVALUE_REFERENCES
  41. #define BOOST_INTERPROCESS_PP_PARAM(U, u) \
  42. U && u \
  43. //!
  44. #else
  45. #define BOOST_INTERPROCESS_PP_PARAM(U, u) \
  46. const U & u \
  47. //!
  48. #endif
  49. #ifndef BOOST_NO_RVALUE_REFERENCES
  50. #define BOOST_INTERPROCESS_PP_PARAM_INIT(z, n, data) \
  51. BOOST_PP_CAT(m_p, n) (::boost::forward< BOOST_PP_CAT(P, n) >( BOOST_PP_CAT(p, n) )) \
  52. //!
  53. #else //#ifndef BOOST_NO_RVALUE_REFERENCES
  54. #define BOOST_INTERPROCESS_PP_PARAM_INIT(z, n, data) \
  55. BOOST_PP_CAT(m_p, n) (const_cast<BOOST_PP_CAT(P, n) &>(BOOST_PP_CAT(p, n))) \
  56. //!
  57. #endif
  58. #ifndef BOOST_NO_RVALUE_REFERENCES
  59. #if defined(BOOST_MOVE_MSVC_10_MEMBER_RVALUE_REF_BUG)
  60. namespace boost {
  61. namespace interprocess {
  62. namespace ipcdetail {
  63. template<class T>
  64. struct ref_holder;
  65. template<class T>
  66. struct ref_holder<T &>
  67. {
  68. ref_holder(T &t)
  69. : t_(t)
  70. {}
  71. T &t_;
  72. T & get() { return t_; }
  73. T & get_lvalue() { return t_; }
  74. };
  75. template<class T>
  76. struct ref_holder<const T>
  77. {
  78. ref_holder(const T &t)
  79. : t_(t)
  80. {}
  81. const T &t_;
  82. const T & get() { return t_; }
  83. const T & get_lvalue() { return t_; }
  84. };
  85. template<class T>
  86. struct ref_holder<const T &&>
  87. {
  88. ref_holder(const T &t)
  89. : t_(t)
  90. {}
  91. const T &t_;
  92. const T & get() { return t_; }
  93. const T & get_lvalue() { return t_; }
  94. };
  95. template<class T>
  96. struct ref_holder
  97. {
  98. ref_holder(T &&t)
  99. : t_(t)
  100. {}
  101. T &t_;
  102. T && get() { return ::boost::move(t_); }
  103. T & get_lvalue() { return t_; }
  104. };
  105. template<class T>
  106. struct ref_holder<T &&>
  107. {
  108. ref_holder(T &&t)
  109. : t(t)
  110. {}
  111. T &t;
  112. T && get() { return ::boost::move(t_); }
  113. T & get_lvalue() { return t_; }
  114. };
  115. } //namespace ipcdetail {
  116. } //namespace interprocess {
  117. } //namespace boost {
  118. #define BOOST_INTERPROCESS_PP_PARAM_DEFINE(z, n, data) \
  119. ::boost::interprocess::ipcdetail::ref_holder<BOOST_PP_CAT(P, n)> BOOST_PP_CAT(m_p, n); \
  120. //!
  121. #define BOOST_INTERPROCESS_PP_PARAM_INC(z, n, data) \
  122. BOOST_PP_CAT(++m_p, n).get_lvalue() \
  123. //!
  124. #else //BOOST_MOVE_MSVC_10_MEMBER_RVALUE_REF_BUG
  125. #define BOOST_INTERPROCESS_PP_PARAM_DEFINE(z, n, data)\
  126. BOOST_PP_CAT(P, n) && BOOST_PP_CAT(m_p, n); \
  127. //!
  128. #define BOOST_INTERPROCESS_PP_PARAM_INC(z, n, data) \
  129. BOOST_PP_CAT(++m_p, n) \
  130. //!
  131. #endif //defined(BOOST_MOVE_MSVC_10_MEMBER_RVALUE_REF_BUG)
  132. #else
  133. #define BOOST_INTERPROCESS_PP_PARAM_DEFINE(z, n, data) \
  134. BOOST_PP_CAT(P, n) & BOOST_PP_CAT(m_p, n); \
  135. //!
  136. #define BOOST_INTERPROCESS_PP_PARAM_INC(z, n, data) \
  137. BOOST_PP_CAT(++m_p, n) \
  138. //!
  139. #endif
  140. #define BOOST_INTERPROCESS_PP_PARAM_FORWARD(z, n, data) \
  141. ::boost::forward< BOOST_PP_CAT(P, n) >( BOOST_PP_CAT(p, n) ) \
  142. //!
  143. #if !defined(BOOST_NO_RVALUE_REFERENCES) && defined(BOOST_MOVE_MSVC_10_MEMBER_RVALUE_REF_BUG)
  144. #define BOOST_INTERPROCESS_PP_MEMBER_FORWARD(z, n, data) BOOST_PP_CAT(this->m_p, n).get() \
  145. //!
  146. #define BOOST_INTERPROCESS_PP_MEMBER_IT_FORWARD(z, n, data) \
  147. BOOST_PP_CAT(*m_p, n).get_lvalue() \
  148. //!
  149. #else
  150. #define BOOST_INTERPROCESS_PP_MEMBER_FORWARD(z, n, data) \
  151. ::boost::forward< BOOST_PP_CAT(P, n) >( BOOST_PP_CAT(m_p, n) ) \
  152. //!
  153. #define BOOST_INTERPROCESS_PP_MEMBER_IT_FORWARD(z, n, data) \
  154. BOOST_PP_CAT(*m_p, n) \
  155. //!
  156. #endif //!defined(BOOST_NO_RVALUE_REFERENCES) && defined(BOOST_MOVE_MSVC_10_MEMBER_RVALUE_REF_BUG)
  157. #include <boost/interprocess/detail/config_end.hpp>
  158. #else
  159. #ifdef BOOST_INTERPROCESS_PERFECT_FORWARDING
  160. #error "This file is not needed when perfect forwarding is available"
  161. #endif
  162. #endif //#ifndef BOOST_INTERPROCESS_DETAIL_PREPROCESSOR_HPP