check_map.hpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. // Boost.TypeErasure library
  2. //
  3. // Copyright 2012 Steven Watanabe
  4. //
  5. // Distributed under the Boost Software License Version 1.0. (See
  6. // accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //
  9. // $Id$
  10. #ifndef BOOST_TYPE_ERASURE_DETAIL_CHECK_MAP_HPP_INCLUDED
  11. #define BOOST_TYPE_ERASURE_DETAIL_CHECK_MAP_HPP_INCLUDED
  12. #include <boost/mpl/not.hpp>
  13. #include <boost/mpl/or.hpp>
  14. #include <boost/mpl/bool.hpp>
  15. #include <boost/mpl/set.hpp>
  16. #include <boost/mpl/has_key.hpp>
  17. #include <boost/mpl/find_if.hpp>
  18. #include <boost/mpl/fold.hpp>
  19. #include <boost/mpl/end.hpp>
  20. #include <boost/type_traits/is_same.hpp>
  21. #include <boost/type_erasure/detail/get_placeholders.hpp>
  22. #include <boost/type_erasure/detail/normalize.hpp>
  23. #include <boost/type_erasure/deduced.hpp>
  24. #include <boost/type_erasure/static_binding.hpp>
  25. namespace boost {
  26. namespace type_erasure {
  27. namespace detail {
  28. template<class T>
  29. struct is_deduced : boost::mpl::false_ {};
  30. template<class T>
  31. struct is_deduced< ::boost::type_erasure::deduced<T> > : boost::mpl::true_ {};
  32. // returns true if Map has a key for every non-deduced placeholder in Concept
  33. template<class Concept, class Map>
  34. struct check_map {
  35. #ifndef BOOST_TYPE_ERASURE_USE_MP11
  36. typedef typename normalize_concept<Concept>::basic basic_components;
  37. typedef typename ::boost::mpl::fold<
  38. basic_components,
  39. ::boost::mpl::set0<>,
  40. ::boost::type_erasure::detail::get_placeholders<
  41. ::boost::mpl::_2,
  42. ::boost::mpl::_1
  43. >
  44. >::type placeholders;
  45. // Every non-deduced placeholder referenced in this
  46. // map is indirectly deduced.
  47. typedef typename ::boost::type_erasure::detail::get_placeholder_normalization_map<
  48. Concept>::type placeholder_subs;
  49. typedef typename ::boost::mpl::fold<
  50. placeholder_subs,
  51. ::boost::mpl::set0<>,
  52. ::boost::mpl::insert<
  53. ::boost::mpl::_1,
  54. ::boost::mpl::second< ::boost::mpl::_2>
  55. >
  56. >::type indirect_deduced_placeholders;
  57. typedef typename ::boost::is_same<
  58. typename ::boost::mpl::find_if<
  59. placeholders,
  60. ::boost::mpl::not_<
  61. ::boost::mpl::or_<
  62. ::boost::type_erasure::detail::is_deduced< ::boost::mpl::_1>,
  63. ::boost::mpl::has_key<Map, ::boost::mpl::_1>,
  64. ::boost::mpl::has_key<indirect_deduced_placeholders, ::boost::mpl::_1>
  65. >
  66. >
  67. >::type,
  68. typename ::boost::mpl::end<placeholders>::type
  69. >::type type;
  70. #else
  71. typedef ::boost::type_erasure::detail::get_all_placeholders<
  72. ::boost::type_erasure::detail::normalize_concept_t<Concept>
  73. > placeholders;
  74. // Every non-deduced placeholder referenced in this
  75. // map is indirectly deduced.
  76. typedef typename ::boost::type_erasure::detail::get_placeholder_normalization_map<
  77. Concept>::type placeholder_subs;
  78. typedef ::boost::mp11::mp_unique<
  79. ::boost::mp11::mp_append<
  80. ::boost::mp11::mp_transform<
  81. ::boost::mp11::mp_first,
  82. ::boost::type_erasure::detail::make_mp_list<Map>
  83. >,
  84. ::boost::mp11::mp_transform<
  85. ::boost::mp11::mp_second,
  86. ::boost::type_erasure::detail::make_mp_list<placeholder_subs>
  87. >
  88. >
  89. > okay_placeholders;
  90. template<class P>
  91. using check_placeholder = ::boost::mpl::or_<
  92. ::boost::type_erasure::detail::is_deduced<P>,
  93. ::boost::mp11::mp_set_contains<okay_placeholders, P>
  94. >;
  95. typedef ::boost::mp11::mp_all_of<placeholders, check_placeholder> type;
  96. #endif
  97. };
  98. template<class Concept, class Map>
  99. struct check_map<Concept, ::boost::type_erasure::static_binding<Map> > :
  100. check_map<Concept, Map>
  101. {};
  102. }
  103. }
  104. }
  105. #endif