that_ptr.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*=============================================================================
  2. Copyright (c) 2006-2007 Tobias Schwinger
  3. Use modification and distribution are subject to the Boost Software
  4. License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. http://www.boost.org/LICENSE_1_0.txt).
  6. ==============================================================================*/
  7. #if !defined(BOOST_FUSION_FUNCTIONAL_INVOCATION_DETAIL_THAT_PTR_HPP_INCLUDED)
  8. #define BOOST_FUSION_FUNCTIONAL_INVOCATION_DETAIL_THAT_PTR_HPP_INCLUDED
  9. #include <boost/fusion/support/config.hpp>
  10. #include <boost/get_pointer.hpp>
  11. #include <boost/utility/addressof.hpp>
  12. #include <boost/type_traits/remove_reference.hpp>
  13. namespace boost { namespace fusion { namespace detail
  14. {
  15. template <typename Wanted>
  16. struct that_ptr
  17. {
  18. private:
  19. typedef typename remove_reference<Wanted>::type pointee;
  20. template <typename T>
  21. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  22. static inline pointee * do_get_pointer(T &, pointee * x)
  23. {
  24. return x;
  25. }
  26. template <typename T>
  27. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  28. static inline pointee * do_get_pointer(T & x, void const *)
  29. {
  30. return get_pointer(x);
  31. }
  32. public:
  33. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  34. static inline pointee * get(pointee * x)
  35. {
  36. return x;
  37. }
  38. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  39. static inline pointee * get(pointee & x)
  40. {
  41. return boost::addressof(x);
  42. }
  43. template <typename T>
  44. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  45. static inline pointee * get(T & x)
  46. {
  47. return do_get_pointer(x, boost::addressof(x));
  48. }
  49. };
  50. template <typename PtrOrSmartPtr> struct non_const_pointee;
  51. #if defined(BOOST_MSVC) || (defined(__BORLANDC__) && !defined(BOOST_DISABLE_WIN32))
  52. # define BOOST_FUSION_TRAIT_DECL __cdecl
  53. #else
  54. # define BOOST_FUSION_TRAIT_DECL /**/
  55. #endif
  56. namespace adl_barrier
  57. {
  58. using boost::get_pointer;
  59. void const * BOOST_FUSION_TRAIT_DECL get_pointer(...); // fallback
  60. template< typename T> char const_tester(T *);
  61. template< typename T> long const_tester(T const *);
  62. template <typename Ptr>
  63. struct non_const_pointee_impl
  64. {
  65. static Ptr & what;
  66. static bool const value =
  67. sizeof(const_tester(get_pointer(what))) == 1;
  68. };
  69. }
  70. template <typename PtrOrSmartPtr> struct non_const_pointee
  71. : adl_barrier::non_const_pointee_impl<
  72. typename remove_cv<
  73. typename remove_reference<PtrOrSmartPtr>::type >::type >
  74. {
  75. typedef non_const_pointee type;
  76. typedef bool value_type;
  77. };
  78. }}}
  79. #endif