access.hpp 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. // Boost.TypeErasure library
  2. //
  3. // Copyright 2011 Steven Watanabe
  4. //
  5. // Distributed under the Boost Software License Version 1.0. (See
  6. // accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //
  9. // $Id$
  10. #ifndef BOOST_TYPE_ERASURE_DETAIL_ACCESS_HPP_INCLUDED
  11. #define BOOST_TYPE_ERASURE_DETAIL_ACCESS_HPP_INCLUDED
  12. #include <boost/type_erasure/detail/storage.hpp>
  13. #include <boost/type_erasure/detail/any_base.hpp>
  14. #if !defined(BOOST_NO_CXX11_RVALUE_REFERENCES) && \
  15. !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && \
  16. !defined(BOOST_NO_CXX11_FUNCTION_TEMPLATE_DEFAULT_ARGS) && \
  17. !defined(BOOST_NO_CXX11_TEMPLATE_ALIASES) && \
  18. !BOOST_WORKAROUND(BOOST_MSVC, == 1800) && \
  19. !BOOST_WORKAROUND(BOOST_GCC, < 40800) && /* Inherited constructors */ \
  20. !(defined(__clang_major__) && __clang_major__ == 3 && __clang__minor__ <= 2) /* Inherited constructors */
  21. #define BOOST_TYPE_ERASURE_SFINAE_FRIENDLY_CONSTRUCTORS
  22. #include <boost/type_traits/is_reference.hpp>
  23. #include <boost/utility/enable_if.hpp>
  24. #endif
  25. namespace boost {
  26. namespace type_erasure {
  27. template<class Concept, class T>
  28. class any;
  29. template<class Concept, class T>
  30. class param;
  31. template<class Concept>
  32. class binding;
  33. namespace detail {
  34. struct access
  35. {
  36. template<class Derived>
  37. static const typename Derived::table_type&
  38. table(const ::boost::type_erasure::any_base<Derived>& arg)
  39. {
  40. return static_cast<const Derived&>(arg).table;
  41. }
  42. template<class Concept, class T>
  43. static const ::boost::type_erasure::binding<Concept>&
  44. table(const ::boost::type_erasure::param<Concept, T>& arg)
  45. {
  46. return table(arg._impl);
  47. }
  48. template<class Concept, class T>
  49. static const ::boost::type_erasure::binding<Concept>&
  50. table(const ::boost::type_erasure::param<Concept, T&>& arg)
  51. {
  52. return arg._impl.table;
  53. }
  54. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  55. template<class Concept, class T>
  56. static const ::boost::type_erasure::binding<Concept>&
  57. table(const ::boost::type_erasure::param<Concept, T&&>& arg)
  58. {
  59. return arg._impl.table;
  60. }
  61. #endif
  62. #ifdef BOOST_TYPE_ERASURE_SFINAE_FRIENDLY_CONSTRUCTORS
  63. template<class Concept, class T, class = typename ::boost::enable_if_c<!::boost::is_reference<T>::value>::type>
  64. static const typename any<Concept, T>::table_type&
  65. table(const ::boost::type_erasure::any_base< ::boost::type_erasure::any<Concept, T> >& arg)
  66. {
  67. return static_cast<const ::boost::type_erasure::any<Concept, T>&>(arg)._boost_type_erasure_table;
  68. }
  69. template<class Concept, class T>
  70. static ::boost::type_erasure::detail::storage&
  71. data(::boost::type_erasure::any_base< ::boost::type_erasure::any<Concept, T> >& arg)
  72. {
  73. return static_cast< ::boost::type_erasure::any<Concept, T>&>(arg)._boost_type_erasure_data;
  74. }
  75. template<class Concept, class T>
  76. static const ::boost::type_erasure::detail::storage&
  77. data(const ::boost::type_erasure::any_base< ::boost::type_erasure::any<Concept, T> >& arg)
  78. {
  79. return static_cast<const ::boost::type_erasure::any<Concept, T>&>(arg)._boost_type_erasure_data;
  80. }
  81. template<class Concept, class T>
  82. static ::boost::type_erasure::detail::storage&&
  83. data(::boost::type_erasure::any_base< ::boost::type_erasure::any<Concept, T> >&& arg)
  84. {
  85. return std::move(static_cast< ::boost::type_erasure::any<Concept, T>&&>(arg)._boost_type_erasure_data);
  86. }
  87. #endif
  88. template<class Derived>
  89. static ::boost::type_erasure::detail::storage&
  90. data(::boost::type_erasure::any_base<Derived>& arg)
  91. {
  92. return static_cast<Derived&>(arg).data;
  93. }
  94. template<class Concept, class T>
  95. static const ::boost::type_erasure::detail::storage&
  96. data(::boost::type_erasure::any_base< ::boost::type_erasure::any<Concept, const T&> >& arg)
  97. {
  98. return static_cast< ::boost::type_erasure::any<Concept, const T&>&>(arg).data;
  99. }
  100. template<class Derived>
  101. static const ::boost::type_erasure::detail::storage&
  102. data(const ::boost::type_erasure::any_base<Derived>& arg)
  103. {
  104. return static_cast<const Derived&>(arg).data;
  105. }
  106. template<class Concept, class T>
  107. static ::boost::type_erasure::detail::storage&
  108. data(::boost::type_erasure::any_base< ::boost::type_erasure::any<Concept, T&> >& arg)
  109. {
  110. return const_cast< ::boost::type_erasure::detail::storage&>(static_cast< ::boost::type_erasure::any<Concept, T&>&>(arg).data);
  111. }
  112. template<class Concept, class T>
  113. static ::boost::type_erasure::detail::storage&
  114. data(const ::boost::type_erasure::any_base< ::boost::type_erasure::any<Concept, T&> >& arg)
  115. {
  116. return const_cast< ::boost::type_erasure::detail::storage&>(static_cast< const ::boost::type_erasure::any<Concept, T&>&>(arg).data);
  117. }
  118. template<class Concept, class T>
  119. static const ::boost::type_erasure::detail::storage&
  120. data(const ::boost::type_erasure::any_base< ::boost::type_erasure::any<Concept, const T&> >& arg)
  121. {
  122. return static_cast<const ::boost::type_erasure::any<Concept, const T&>&>(arg).data;
  123. }
  124. template<class Concept, class T>
  125. static ::boost::type_erasure::detail::storage&
  126. data(::boost::type_erasure::param<Concept, T>& arg)
  127. {
  128. return data(arg._impl);
  129. }
  130. template<class Concept, class T>
  131. static ::boost::type_erasure::detail::storage&
  132. data(::boost::type_erasure::param<Concept, T&>& arg)
  133. {
  134. return arg._impl.data;
  135. }
  136. template<class Concept, class T>
  137. static const ::boost::type_erasure::detail::storage&
  138. data(::boost::type_erasure::param<Concept, const T&>& arg)
  139. {
  140. return arg._impl.data;
  141. }
  142. template<class Concept, class T>
  143. static const ::boost::type_erasure::detail::storage&
  144. data(const ::boost::type_erasure::param<Concept, T>& arg)
  145. {
  146. return data(arg._impl);
  147. }
  148. template<class Concept, class T>
  149. static const ::boost::type_erasure::detail::storage&
  150. data(const ::boost::type_erasure::param<Concept, T&>& arg)
  151. {
  152. return arg._impl.data;
  153. }
  154. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  155. template<class Derived>
  156. static ::boost::type_erasure::detail::storage&&
  157. data(::boost::type_erasure::any_base<Derived>&& arg)
  158. {
  159. return std::move(static_cast<Derived&>(arg).data);
  160. }
  161. template<class Concept, class T>
  162. static ::boost::type_erasure::detail::storage&&
  163. data(::boost::type_erasure::any_base< ::boost::type_erasure::any<Concept, T&&> >& arg)
  164. {
  165. return std::move(static_cast< ::boost::type_erasure::any<Concept, T&&>&>(arg).data);
  166. }
  167. template<class Concept, class T>
  168. static ::boost::type_erasure::detail::storage&&
  169. data(::boost::type_erasure::any_base< ::boost::type_erasure::any<Concept, T&&> >&& arg)
  170. {
  171. return std::move(static_cast< ::boost::type_erasure::any<Concept, T&&>&>(arg).data);
  172. }
  173. template<class Concept, class T>
  174. static ::boost::type_erasure::detail::storage&&
  175. data(const ::boost::type_erasure::any_base< ::boost::type_erasure::any<Concept, T&&> >& arg)
  176. {
  177. return std::move(const_cast< ::boost::type_erasure::detail::storage&>(static_cast< const ::boost::type_erasure::any<Concept, T&&>&>(arg).data));
  178. }
  179. template<class Concept, class T>
  180. static ::boost::type_erasure::detail::storage&
  181. data(::boost::type_erasure::any_base< ::boost::type_erasure::any<Concept, T&> >&& arg)
  182. {
  183. return std::move(static_cast< ::boost::type_erasure::any<Concept, T&>&>(arg).data);
  184. }
  185. template<class Concept, class T>
  186. static ::boost::type_erasure::detail::storage&&
  187. data(::boost::type_erasure::param<Concept, T>&& arg)
  188. {
  189. return std::move(data(arg._impl));
  190. }
  191. template<class Concept, class T>
  192. static ::boost::type_erasure::detail::storage&&
  193. data(::boost::type_erasure::param<Concept, T&&>&& arg)
  194. {
  195. return std::move(arg._impl.data);
  196. }
  197. template<class Concept, class T>
  198. static ::boost::type_erasure::detail::storage&
  199. data(::boost::type_erasure::param<Concept, T&>&& arg)
  200. {
  201. return arg._impl.data;
  202. }
  203. template<class Concept, class T>
  204. static const ::boost::type_erasure::detail::storage&
  205. data(::boost::type_erasure::param<Concept, const T&>&& arg)
  206. {
  207. return arg._impl.data;
  208. }
  209. template<class Concept, class T>
  210. static ::boost::type_erasure::detail::storage&&
  211. data(::boost::type_erasure::param<Concept, T&&>& arg)
  212. {
  213. return std::move(arg._impl.data);
  214. }
  215. template<class Concept, class T>
  216. static ::boost::type_erasure::detail::storage&&
  217. data(const ::boost::type_erasure::param<Concept, T&&>& arg)
  218. {
  219. return std::move(const_cast< ::boost::type_erasure::detail::storage&>(arg._impl.data));
  220. }
  221. #endif
  222. };
  223. }
  224. }
  225. }
  226. #endif