/Src/Dependencies/Boost/boost/fusion/sequence/intrinsic/at_key.hpp

http://hadesmem.googlecode.com/ · C++ Header · 92 lines · 72 code · 12 blank · 8 comment · 0 complexity · 646de4de31e25c0f7596f6d31692bdb4 MD5 · raw file

  1. /*=============================================================================
  2. Copyright (c) 2001-2006 Joel de Guzman
  3. Copyright (c) 2006 Dan Marsden
  4. Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. ==============================================================================*/
  7. #if !defined(BOOST_FUSION_AT_KEY_20060304_1755)
  8. #define BOOST_FUSION_AT_KEY_20060304_1755
  9. #include <boost/type_traits/is_const.hpp>
  10. #include <boost/fusion/algorithm/query/find.hpp>
  11. #include <boost/fusion/iterator/deref_data.hpp>
  12. #include <boost/fusion/support/tag_of.hpp>
  13. #include <boost/fusion/support/detail/access.hpp>
  14. namespace boost { namespace fusion
  15. {
  16. // Special tags:
  17. struct sequence_facade_tag;
  18. struct boost_array_tag; // boost::array tag
  19. struct mpl_sequence_tag; // mpl sequence tag
  20. struct std_pair_tag; // std::pair tag
  21. namespace extension
  22. {
  23. template <typename Tag>
  24. struct at_key_impl
  25. {
  26. template <typename Seq, typename Key>
  27. struct apply
  28. {
  29. typedef typename
  30. result_of::deref_data<
  31. typename result_of::find<Seq, Key>::type
  32. >::type
  33. type;
  34. static type
  35. call(Seq& seq)
  36. {
  37. return fusion::deref_data(fusion::find<Key>(seq));
  38. }
  39. };
  40. };
  41. template <>
  42. struct at_key_impl<sequence_facade_tag>
  43. {
  44. template <typename Sequence, typename Key>
  45. struct apply : Sequence::template at_key_impl<Sequence, Key> {};
  46. };
  47. template <>
  48. struct at_key_impl<boost_array_tag>;
  49. template <>
  50. struct at_key_impl<mpl_sequence_tag>;
  51. template <>
  52. struct at_key_impl<std_pair_tag>;
  53. }
  54. namespace result_of
  55. {
  56. template <typename Sequence, typename Key>
  57. struct at_key
  58. : extension::at_key_impl<typename detail::tag_of<Sequence>::type>::
  59. template apply<Sequence, Key>
  60. {};
  61. }
  62. template <typename Key, typename Sequence>
  63. inline typename
  64. lazy_disable_if<
  65. is_const<Sequence>
  66. , result_of::at_key<Sequence, Key>
  67. >::type
  68. at_key(Sequence& seq)
  69. {
  70. return result_of::at_key<Sequence, Key>::call(seq);
  71. }
  72. template <typename Key, typename Sequence>
  73. inline typename result_of::at_key<Sequence const, Key>::type
  74. at_key(Sequence const& seq)
  75. {
  76. return result_of::at_key<Sequence const, Key>::call(seq);
  77. }
  78. }}
  79. #endif