]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Copyright 2008-2010 Gordon Woodhull |
2 | // Distributed under the Boost Software License, Version 1.0. | |
3 | // (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) | |
4 | ||
5 | #ifndef BOOST_MSM_MPL_GRAPH_MPL_UTILS_HPP_INCLUDED | |
6 | #define BOOST_MSM_MPL_GRAPH_MPL_UTILS_HPP_INCLUDED | |
7 | ||
8 | #include <boost/mpl/fold.hpp> | |
9 | #include <boost/mpl/map.hpp> | |
10 | #include <boost/mpl/set.hpp> | |
11 | #include <boost/mpl/insert.hpp> | |
12 | #include <boost/mpl/if.hpp> | |
13 | #include <boost/mpl/has_key.hpp> | |
14 | #include <boost/mpl/at.hpp> | |
15 | #include <boost/mpl/and.hpp> | |
16 | ||
17 | namespace boost { | |
18 | namespace msm { | |
19 | namespace mpl_graph { | |
20 | namespace mpl_utils { | |
21 | ||
22 | // This is a grab bag of little metafunctions I expect already | |
23 | // exist under some name I haven't looked for | |
24 | ||
25 | // I figure there are probably better ways to do all of these things, | |
26 | // but for now I'll just write some utilities to isolate my ignorance | |
27 | ||
28 | template<typename Seq> | |
29 | struct as_map : | |
30 | mpl::fold<Seq, | |
31 | mpl::map<>, | |
32 | mpl::insert<mpl::_1, mpl::_2> > | |
33 | {}; | |
34 | template<typename Seq> | |
35 | struct as_set : | |
36 | mpl::fold<Seq, | |
37 | mpl::set<>, | |
38 | mpl::insert<mpl::_1, mpl::_2> > | |
39 | {}; | |
40 | ||
41 | template<typename AssocSeq, typename Key, typename Default> | |
42 | struct at_or_default : | |
43 | mpl::if_<typename mpl::has_key<AssocSeq, Key>::type, | |
44 | typename mpl::at<AssocSeq, Key>::type, | |
45 | Default> | |
46 | {}; | |
47 | ||
48 | template<typename Seq1, typename Seq2> | |
49 | struct set_equal : | |
50 | mpl::fold<Seq2, | |
51 | mpl::true_, | |
52 | mpl::and_<mpl::_1, | |
53 | mpl::has_key<typename as_set<Seq1>::type, | |
54 | mpl::_2 > > > | |
55 | {}; | |
56 | ||
57 | } | |
58 | } | |
59 | } | |
60 | } | |
61 | ||
62 | #endif // BOOST_MSM_MPL_GRAPH_MPL_UTILS_HPP_INCLUDED |