has_key.hpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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/support/config.hpp>
  9. #include <boost/fusion/sequence/intrinsic_fwd.hpp>
  10. #include <boost/fusion/support/tag_of.hpp>
  11. #include <boost/fusion/iterator/equal_to.hpp>
  12. #include <boost/fusion/algorithm/query/find.hpp>
  13. #include <boost/fusion/sequence/intrinsic/end.hpp>
  14. #include <boost/mpl/not.hpp>
  15. namespace boost { namespace fusion
  16. {
  17. struct void_;
  18. // Special tags:
  19. struct sequence_facade_tag;
  20. struct boost_array_tag; // boost::array tag
  21. struct mpl_sequence_tag; // mpl sequence tag
  22. struct std_pair_tag; // std::pair tag
  23. namespace extension
  24. {
  25. template <typename Tag>
  26. struct has_key_impl
  27. {
  28. template <typename Seq, typename Key>
  29. struct apply
  30. : mpl::not_<
  31. typename result_of::equal_to<
  32. typename result_of::find<Seq, Key>::type
  33. , typename result_of::end<Seq>::type
  34. >::type
  35. >::type
  36. {};
  37. };
  38. template <>
  39. struct has_key_impl<sequence_facade_tag>
  40. {
  41. template <typename Sequence, typename Key>
  42. struct apply : Sequence::template has_key<Sequence, Key> {};
  43. };
  44. template <>
  45. struct has_key_impl<boost_array_tag>;
  46. template <>
  47. struct has_key_impl<mpl_sequence_tag>;
  48. template <>
  49. struct has_key_impl<std_pair_tag>;
  50. }
  51. namespace result_of
  52. {
  53. template <typename Sequence, typename Key>
  54. struct has_key
  55. : extension::has_key_impl<typename detail::tag_of<Sequence>::type>::
  56. template apply<Sequence, Key>
  57. {};
  58. }
  59. template <typename Key, typename Sequence>
  60. BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
  61. inline typename result_of::has_key<Sequence, Key>::type
  62. has_key(Sequence const&)
  63. {
  64. typedef typename result_of::has_key<Sequence, Key>::type result;
  65. return result();
  66. }
  67. }}
  68. #endif