has_key.hpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*=============================================================================
  2. Copyright (c) 2001-2011 Joel de Guzman
  3. Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. ==============================================================================*/
  6. #if !defined(FUSION_HAS_KEY_09232005_1454)
  7. #define FUSION_HAS_KEY_09232005_1454
  8. #include <boost/fusion/sequence/intrinsic_fwd.hpp>
  9. #include <boost/fusion/support/tag_of.hpp>
  10. #include <boost/fusion/iterator/equal_to.hpp>
  11. #include <boost/fusion/algorithm/query/find.hpp>
  12. #include <boost/fusion/sequence/intrinsic/end.hpp>
  13. #include <boost/mpl/not.hpp>
  14. namespace boost { namespace fusion
  15. {
  16. struct void_;
  17. // Special tags:
  18. struct sequence_facade_tag;
  19. struct boost_array_tag; // boost::array tag
  20. struct mpl_sequence_tag; // mpl sequence tag
  21. struct std_pair_tag; // std::pair tag
  22. namespace extension
  23. {
  24. template <typename Tag>
  25. struct has_key_impl
  26. {
  27. template <typename Seq, typename Key>
  28. struct apply
  29. : mpl::not_<
  30. typename result_of::equal_to<
  31. typename result_of::find<Seq, Key>::type
  32. , typename result_of::end<Seq>::type
  33. >::type
  34. >::type
  35. {};
  36. };
  37. template <>
  38. struct has_key_impl<sequence_facade_tag>
  39. {
  40. template <typename Sequence, typename Key>
  41. struct apply : Sequence::template has_key<Sequence, Key> {};
  42. };
  43. template <>
  44. struct has_key_impl<boost_array_tag>;
  45. template <>
  46. struct has_key_impl<mpl_sequence_tag>;
  47. template <>
  48. struct has_key_impl<std_pair_tag>;
  49. }
  50. namespace result_of
  51. {
  52. template <typename Sequence, typename Key>
  53. struct has_key
  54. : extension::has_key_impl<typename detail::tag_of<Sequence>::type>::
  55. template apply<Sequence, Key>
  56. {};
  57. }
  58. template <typename Key, typename Sequence>
  59. inline typename result_of::has_key<Sequence, Key>::type
  60. has_key(Sequence const&)
  61. {
  62. typedef typename result_of::has_key<Sequence, Key>::type result;
  63. return result();
  64. }
  65. }}
  66. #endif