member_function_types.hpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #ifndef BOOST_CONTRACT_DETAIL_MEMBER_FUNCTION_TYPES_HPP_
  2. #define BOOST_CONTRACT_DETAIL_MEMBER_FUNCTION_TYPES_HPP_
  3. // Copyright (C) 2008-2018 Lorenzo Caminiti
  4. // Distributed under the Boost Software License, Version 1.0 (see accompanying
  5. // file LICENSE_1_0.txt or a copy at http://www.boost.org/LICENSE_1_0.txt).
  6. // See: http://www.boost.org/doc/libs/release/libs/contract/doc/html/index.html
  7. #include <boost/contract/detail/none.hpp>
  8. #include <boost/function_types/parameter_types.hpp>
  9. #include <boost/function_types/result_type.hpp>
  10. #include <boost/function_types/property_tags.hpp>
  11. #include <boost/type_traits/is_const.hpp>
  12. #include <boost/type_traits/is_volatile.hpp>
  13. #include <boost/type_traits/is_same.hpp>
  14. #include <boost/mpl/pop_front.hpp>
  15. #include <boost/mpl/push_back.hpp>
  16. #include <boost/mpl/back.hpp>
  17. #include <boost/mpl/and.hpp>
  18. #include <boost/mpl/if.hpp>
  19. #include <boost/mpl/identity.hpp>
  20. namespace boost {
  21. namespace contract {
  22. class virtual_;
  23. }
  24. }
  25. namespace boost { namespace contract { namespace detail {
  26. template<class C, typename F>
  27. struct member_function_types {
  28. typedef typename boost::function_types::result_type<F>::type result_type;
  29. // Never include leading class type.
  30. typedef typename boost::mpl::pop_front<typename boost::function_types::
  31. parameter_types<F>::type>::type argument_types;
  32. // Always include trailing virtual_* type.
  33. typedef typename boost::mpl::if_<boost::is_same<typename boost::
  34. mpl::back<argument_types>::type, boost::contract::virtual_*>,
  35. boost::mpl::identity<argument_types>
  36. ,
  37. boost::mpl::push_back<argument_types, boost::contract::virtual_*>
  38. >::type::type virtual_argument_types;
  39. typedef typename boost::mpl::if_<boost::mpl::and_<boost::is_const<C>,
  40. boost::is_volatile<C> >,
  41. boost::function_types::cv_qualified
  42. , typename boost::mpl::if_<boost::is_const<C>,
  43. boost::function_types::const_non_volatile
  44. , typename boost::mpl::if_<boost::is_volatile<C>,
  45. boost::function_types::volatile_non_const
  46. ,
  47. boost::function_types::null_tag
  48. >::type>::type>::type property_tag;
  49. };
  50. // Also handles none type.
  51. template<class C>
  52. struct member_function_types<C, none> {
  53. typedef none result_type;
  54. typedef none argument_types;
  55. typedef none virtual_argument_types;
  56. typedef none property_tag;
  57. };
  58. } } } // namespace
  59. #endif // #include guard