that_ptr.hpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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/get_pointer.hpp>
  10. #include <boost/utility/addressof.hpp>
  11. #include <boost/type_traits/config.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. static inline pointee * do_get_pointer(T &, pointee * x)
  22. {
  23. return x;
  24. }
  25. template <typename T>
  26. static inline pointee * do_get_pointer(T & x, void const *)
  27. {
  28. return get_pointer(x);
  29. }
  30. public:
  31. static inline pointee * get(pointee * x)
  32. {
  33. return x;
  34. }
  35. static inline pointee * get(pointee & x)
  36. {
  37. return boost::addressof(x);
  38. }
  39. template <typename T> static inline pointee * get(T & x)
  40. {
  41. return do_get_pointer(x, boost::addressof(x));
  42. }
  43. };
  44. template <typename PtrOrSmartPtr> struct non_const_pointee;
  45. namespace adl_barrier
  46. {
  47. using boost::get_pointer;
  48. void const * BOOST_TT_DECL get_pointer(...); // fallback
  49. template< typename T> char const_tester(T *);
  50. template< typename T> long const_tester(T const *);
  51. template <typename Ptr>
  52. struct non_const_pointee_impl
  53. {
  54. static Ptr & what;
  55. static bool const value =
  56. sizeof(const_tester(get_pointer(what))) == 1;
  57. };
  58. }
  59. template <typename PtrOrSmartPtr> struct non_const_pointee
  60. : adl_barrier::non_const_pointee_impl<
  61. typename remove_cv<
  62. typename remove_reference<PtrOrSmartPtr>::type >::type >
  63. {
  64. typedef non_const_pointee type;
  65. typedef bool value_type;
  66. };
  67. }}}
  68. #endif