File indexing completed on 2025-01-30 10:01:21
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef BOOST_TYPE_ERASURE_DETAIL_CONST_HPP_INCLUDED
0012 #define BOOST_TYPE_ERASURE_DETAIL_CONST_HPP_INCLUDED
0013
0014 #include <boost/mpl/if.hpp>
0015 #include <boost/mpl/bool.hpp>
0016 #include <boost/mpl/or.hpp>
0017 #include <boost/mpl/and.hpp>
0018 #include <boost/mpl/not.hpp>
0019 #include <boost/type_traits/is_same.hpp>
0020 #include <boost/type_traits/is_const.hpp>
0021 #include <boost/type_traits/is_reference.hpp>
0022 #include <boost/type_traits/remove_reference.hpp>
0023 #include <boost/type_traits/remove_cv.hpp>
0024 #include <boost/type_erasure/placeholder_of.hpp>
0025 #include <boost/type_erasure/derived.hpp>
0026
0027 namespace boost {
0028 namespace type_erasure {
0029 namespace detail {
0030
0031 template<class T>
0032 struct is_non_const_ref : boost::mpl::false_ {};
0033 template<class T>
0034 struct is_non_const_ref<T&> : boost::mpl::true_ {};
0035 template<class T>
0036 struct is_non_const_ref<const T&> : boost::mpl::false_ {};
0037
0038 template<class Placeholder, class Base>
0039 struct should_be_const :
0040 ::boost::mpl::or_<
0041 ::boost::is_const<Placeholder>,
0042 ::boost::type_erasure::detail::is_non_const_ref<
0043 typename ::boost::type_erasure::placeholder_of<Base>::type
0044 >
0045 >
0046 {};
0047
0048 template<class Placeholder, class Base>
0049 struct should_be_non_const :
0050 ::boost::mpl::and_<
0051 ::boost::mpl::not_< ::boost::is_const<Placeholder> >,
0052 ::boost::mpl::not_<
0053 ::boost::is_reference<
0054 typename ::boost::type_erasure::placeholder_of<Base>::type
0055 >
0056 >
0057 >
0058 {};
0059
0060 template<class Base>
0061 struct non_const_this_param
0062 {
0063 typedef typename ::boost::type_erasure::placeholder_of<Base>::type placeholder;
0064 typedef typename ::boost::type_erasure::derived<Base>::type plain_type;
0065 typedef typename ::boost::mpl::if_<
0066 ::boost::is_same<
0067 placeholder,
0068 typename ::boost::remove_cv<
0069 typename ::boost::remove_reference<placeholder>::type
0070 >::type&
0071 >,
0072 const plain_type,
0073 plain_type
0074 >::type type;
0075 };
0076
0077 template<class T>
0078 struct uncallable {};
0079
0080 template<class Placeholder, class Base>
0081 struct maybe_const_this_param
0082 {
0083 typedef typename ::boost::type_erasure::derived<Base>::type plain_type;
0084 typedef typename ::boost::remove_reference<Placeholder>::type plain_placeholder;
0085 typedef typename ::boost::mpl::if_< ::boost::is_reference<Placeholder>,
0086 typename ::boost::mpl::if_<
0087 ::boost::type_erasure::detail::should_be_non_const<plain_placeholder, Base>,
0088 plain_type&,
0089 typename ::boost::mpl::if_<
0090 ::boost::type_erasure::detail::should_be_const<plain_placeholder, Base>,
0091 const plain_type&,
0092 uncallable<plain_type>
0093 >::type
0094 >::type,
0095 plain_type
0096 >::type type;
0097 };
0098
0099 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
0100
0101 template<class Placeholder, class Base>
0102 struct maybe_const_this_param<Placeholder&&, Base>
0103 {
0104 typedef typename ::boost::type_erasure::derived<Base>::type plain_type;
0105 typedef typename ::boost::remove_reference<Placeholder>::type plain_placeholder;
0106 typedef typename ::boost::type_erasure::placeholder_of<plain_type>::type self_placeholder;
0107 typedef typename ::boost::mpl::if_< ::boost::is_lvalue_reference<self_placeholder>,
0108 ::boost::type_erasure::detail::uncallable<plain_type>,
0109 typename ::boost::mpl::if_< ::boost::is_rvalue_reference<self_placeholder>,
0110 const plain_type&,
0111 plain_type&&
0112 >::type
0113 >::type type;
0114 };
0115
0116 #endif
0117
0118 }
0119 }
0120 }
0121
0122 #endif