Imported Upstream version 1.57.0
[platform/upstream/boost.git] / boost / type_erasure / detail / check_map.hpp
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
11 #ifndef BOOST_TYPE_ERASURE_DETAIL_CHECK_MAP_HPP_INCLUDED
12 #define BOOST_TYPE_ERASURE_DETAIL_CHECK_MAP_HPP_INCLUDED
13
14 #include <boost/mpl/not.hpp>
15 #include <boost/mpl/or.hpp>
16 #include <boost/mpl/bool.hpp>
17 #include <boost/mpl/set.hpp>
18 #include <boost/mpl/has_key.hpp>
19 #include <boost/mpl/find_if.hpp>
20 #include <boost/mpl/end.hpp>
21 #include <boost/type_traits/is_same.hpp>
22 #include <boost/type_erasure/detail/get_placeholders.hpp>
23 #include <boost/type_erasure/deduced.hpp>
24 #include <boost/type_erasure/static_binding.hpp>
25
26 namespace boost {
27 namespace type_erasure {
28 namespace detail {
29
30 template<class T>
31 struct is_deduced : boost::mpl::false_ {};
32 template<class T>
33 struct is_deduced< ::boost::type_erasure::deduced<T> > : boost::mpl::true_ {};
34
35 // returns true if Map has a key for every non-deduced placeholder in Concept
36 template<class Concept, class Map>
37 struct check_map {
38     typedef typename normalize_concept<Concept>::basic basic_components;
39     
40     // Every non-deduced placeholder referenced in this
41     // map is indirectly deduced.
42     typedef typename ::boost::type_erasure::detail::get_placeholder_normalization_map<
43         Concept>::type placeholder_subs;
44     typedef typename ::boost::mpl::fold<
45         placeholder_subs,
46         ::boost::mpl::set0<>,
47         ::boost::mpl::insert<
48             ::boost::mpl::_1,
49             ::boost::mpl::second< ::boost::mpl::_2>
50         >
51     >::type indirect_deduced_placeholders;
52
53     typedef typename ::boost::mpl::fold<
54         basic_components,
55         ::boost::mpl::set0<>,
56         ::boost::type_erasure::detail::get_placeholders<
57             ::boost::mpl::_2,
58             ::boost::mpl::_1
59         >
60     >::type placeholders;
61     typedef typename ::boost::is_same<
62         typename ::boost::mpl::find_if<
63             placeholders,
64             ::boost::mpl::not_<
65                 ::boost::mpl::or_<
66                     ::boost::type_erasure::detail::is_deduced< ::boost::mpl::_1>,
67                     ::boost::mpl::has_key<Map, ::boost::mpl::_1>,
68                     ::boost::mpl::has_key<indirect_deduced_placeholders, ::boost::mpl::_1>
69                 >
70             >
71         >::type,
72         typename ::boost::mpl::end<placeholders>::type
73     >::type type;
74 };
75
76 template<class Concept, class Map>
77 struct check_map<Concept, ::boost::type_erasure::static_binding<Map> > :
78     check_map<Concept, Map>
79 {};
80
81 }
82 }
83 }
84
85 #endif