composite_member_pointer_type.hpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #ifndef BOOST_TYPE_TRAITS_DETAIL_COMPOSITE_MEMBER_POINTER_TYPE_HPP_INCLUDED
  2. #define BOOST_TYPE_TRAITS_DETAIL_COMPOSITE_MEMBER_POINTER_TYPE_HPP_INCLUDED
  3. //
  4. // Copyright 2015 Peter Dimov
  5. //
  6. // Distributed under the Boost Software License, Version 1.0.
  7. // See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt
  9. //
  10. #include <boost/type_traits/detail/composite_pointer_type.hpp>
  11. #include <boost/type_traits/remove_pointer.hpp>
  12. #include <boost/type_traits/is_base_of.hpp>
  13. #include <boost/type_traits/conditional.hpp>
  14. #include <boost/config.hpp>
  15. #include <cstddef>
  16. namespace boost
  17. {
  18. namespace type_traits_detail
  19. {
  20. template<class T, class U> struct composite_member_pointer_type;
  21. // nullptr_t
  22. #if !defined( BOOST_NO_CXX11_NULLPTR )
  23. #if !defined( BOOST_NO_CXX11_DECLTYPE ) && ( ( defined( __clang__ ) && !defined( _LIBCPP_VERSION ) ) || defined( __INTEL_COMPILER ) )
  24. template<class C, class T> struct composite_member_pointer_type<T C::*, decltype(nullptr)>
  25. {
  26. typedef T C::* type;
  27. };
  28. template<class C, class T> struct composite_member_pointer_type<decltype(nullptr), T C::*>
  29. {
  30. typedef T C::* type;
  31. };
  32. template<> struct composite_member_pointer_type<decltype(nullptr), decltype(nullptr)>
  33. {
  34. typedef decltype(nullptr) type;
  35. };
  36. #else
  37. template<class C, class T> struct composite_member_pointer_type<T C::*, std::nullptr_t>
  38. {
  39. typedef T C::* type;
  40. };
  41. template<class C, class T> struct composite_member_pointer_type<std::nullptr_t, T C::*>
  42. {
  43. typedef T C::* type;
  44. };
  45. template<> struct composite_member_pointer_type<std::nullptr_t, std::nullptr_t>
  46. {
  47. typedef std::nullptr_t type;
  48. };
  49. #endif
  50. #endif // !defined( BOOST_NO_CXX11_NULLPTR )
  51. template<class C1, class C2> struct common_member_class;
  52. template<class C> struct common_member_class<C, C>
  53. {
  54. typedef C type;
  55. };
  56. template<class C1, class C2> struct common_member_class
  57. {
  58. typedef typename boost::conditional<
  59. boost::is_base_of<C1, C2>::value,
  60. C2,
  61. typename boost::conditional<boost::is_base_of<C2, C1>::value, C1, void>::type
  62. >::type type;
  63. };
  64. //This indirection avoids compilation errors on some older
  65. //compilers like MSVC 7.1
  66. template<class CT, class CB>
  67. struct common_member_class_pointer_to_member
  68. {
  69. typedef CT CB::* type;
  70. };
  71. template<class C1, class T1, class C2, class T2> struct composite_member_pointer_type<T1 C1::*, T2 C2::*>
  72. {
  73. private:
  74. typedef typename composite_pointer_type<T1*, T2*>::type CPT;
  75. typedef typename boost::remove_pointer<CPT>::type CT;
  76. typedef typename common_member_class<C1, C2>::type CB;
  77. public:
  78. typedef typename common_member_class_pointer_to_member<CT, CB>::type type;
  79. };
  80. } // namespace type_traits_detail
  81. } // namespace boost
  82. #endif // #ifndef BOOST_TYPE_TRAITS_DETAIL_COMPOSITE_MEMBER_POINTER_TYPE_HPP_INCLUDED