1 // Boost.TypeErasure library
3 // Copyright 2012 Steven Watanabe
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)
11 #ifndef BOOST_TYPE_ERASURE_IS_SUBCONCEPT_HPP_INCLUDED
12 #define BOOST_TYPE_ERASURE_IS_SUBCONCEPT_HPP_INCLUDED
14 #include <boost/mpl/bool.hpp>
15 #include <boost/mpl/not.hpp>
16 #include <boost/mpl/if.hpp>
17 #include <boost/mpl/end.hpp>
18 #include <boost/mpl/find_if.hpp>
19 #include <boost/mpl/has_key.hpp>
20 #include <boost/type_traits/is_same.hpp>
21 #include <boost/type_erasure/detail/normalize.hpp>
22 #include <boost/type_erasure/detail/rebind_placeholders.hpp>
23 #include <boost/type_erasure/static_binding.hpp>
26 namespace type_erasure {
29 template<class Sub, class Super, class PlaceholderMap>
30 struct is_subconcept_impl {
31 typedef typename ::boost::type_erasure::detail::normalize_concept<
32 Super>::concept_set super_set;
33 typedef typename ::boost::type_erasure::detail::get_placeholder_normalization_map<
35 >::type placeholder_subs_super;
37 typedef typename ::boost::type_erasure::detail::normalize_concept<
38 Sub>::type normalized_sub;
39 typedef typename ::boost::type_erasure::detail::get_placeholder_normalization_map<
41 >::type placeholder_subs_sub;
43 typedef typename ::boost::mpl::eval_if< ::boost::is_same<PlaceholderMap, void>,
44 boost::mpl::identity<void>,
45 ::boost::type_erasure::detail::convert_deductions<
48 placeholder_subs_super
52 typedef typename ::boost::mpl::if_< ::boost::is_same<PlaceholderMap, void>,
54 ::boost::type_erasure::detail::rebind_placeholders<
60 typedef typename ::boost::is_same<
61 typename ::boost::mpl::find_if<normalized_sub,
63 ::boost::mpl::has_key<
69 typename ::boost::mpl::end<normalized_sub>::type
76 * @ref is_subconcept is a boolean metafunction that determines whether
77 * one concept is a sub-concept of another.
80 * is_subconcept<incrementable<>, incrementable<> > -> true
81 * is_subconcept<incrementable<>, addable<> > -> false
82 * is_subconcept<incrementable<_a>, forward_iterator<_iter>,
83 * mpl::map<mpl::pair<_a, _iter> > > -> true
86 * \tparam Sub The sub concept
87 * \tparam Super The super concept
88 * \tparam PlaceholderMap (optional) An MPL map with keys for
89 * every non-deduced placeholder in Sub. The
90 * associated value of each key is the corresponding placeholder
91 * in Super. If @c PlaceholderMap is omitted, @c Super and @c Sub
92 * are presumed to use the same set of placeholders.
94 template<class Sub, class Super, class PlaceholderMap = void>
95 struct is_subconcept : ::boost::type_erasure::detail::is_subconcept_impl<Sub, Super, PlaceholderMap>::type {
98 #ifndef BOOST_TYPE_ERASURE_DOXYGEN
99 template<class Sub, class Super, class PlaceholderMap>
100 struct is_subconcept<Sub, Super, static_binding<PlaceholderMap> > :
101 ::boost::type_erasure::detail::is_subconcept_impl<Sub, Super, PlaceholderMap>::type