mpl_utils.hpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. #ifndef BOOST_MSM_MPL_GRAPH_MPL_UTILS_HPP_INCLUDED
  5. #define BOOST_MSM_MPL_GRAPH_MPL_UTILS_HPP_INCLUDED
  6. #include <boost/mpl/fold.hpp>
  7. #include <boost/mpl/map.hpp>
  8. #include <boost/mpl/set.hpp>
  9. #include <boost/mpl/insert.hpp>
  10. #include <boost/mpl/if.hpp>
  11. #include <boost/mpl/has_key.hpp>
  12. #include <boost/mpl/at.hpp>
  13. #include <boost/mpl/and.hpp>
  14. namespace boost {
  15. namespace msm {
  16. namespace mpl_graph {
  17. namespace mpl_utils {
  18. // This is a grab bag of little metafunctions I expect already
  19. // exist under some name I haven't looked for
  20. // I figure there are probably better ways to do all of these things,
  21. // but for now I'll just write some utilities to isolate my ignorance
  22. template<typename Seq>
  23. struct as_map :
  24. mpl::fold<Seq,
  25. mpl::map<>,
  26. mpl::insert<mpl::_1, mpl::_2> >
  27. {};
  28. template<typename Seq>
  29. struct as_set :
  30. mpl::fold<Seq,
  31. mpl::set<>,
  32. mpl::insert<mpl::_1, mpl::_2> >
  33. {};
  34. template<typename AssocSeq, typename Key, typename Default>
  35. struct at_or_default :
  36. mpl::if_<typename mpl::has_key<AssocSeq, Key>::type,
  37. typename mpl::at<AssocSeq, Key>::type,
  38. Default>
  39. {};
  40. template<typename Seq1, typename Seq2>
  41. struct set_equal :
  42. mpl::fold<Seq2,
  43. mpl::true_,
  44. mpl::and_<mpl::_1,
  45. mpl::has_key<typename as_set<Seq1>::type,
  46. mpl::_2 > > >
  47. {};
  48. }
  49. }
  50. }
  51. }
  52. #endif // BOOST_MSM_MPL_GRAPH_MPL_UTILS_HPP_INCLUDED