value_at_key.hpp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*=============================================================================
  2. Copyright (c) 2001-2011 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(FUSION_VALUE_AT_KEY_05052005_0229)
  8. #define FUSION_VALUE_AT_KEY_05052005_0229
  9. #include <boost/mpl/int.hpp>
  10. #include <boost/fusion/sequence/intrinsic_fwd.hpp>
  11. #include <boost/fusion/iterator/value_of_data.hpp>
  12. #include <boost/fusion/algorithm/query/find.hpp>
  13. #include <boost/fusion/support/tag_of.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 value_at_key_impl
  25. {
  26. template <typename Seq, typename Key>
  27. struct apply
  28. : result_of::value_of_data<
  29. typename result_of::find<Seq, Key>::type
  30. >
  31. {};
  32. };
  33. template <>
  34. struct value_at_key_impl<sequence_facade_tag>
  35. {
  36. template <typename Sequence, typename Key>
  37. struct apply : Sequence::template value_at_key<Sequence, Key> {};
  38. };
  39. template <>
  40. struct value_at_key_impl<boost_array_tag>;
  41. template <>
  42. struct value_at_key_impl<mpl_sequence_tag>;
  43. template <>
  44. struct value_at_key_impl<std_pair_tag>;
  45. }
  46. namespace result_of
  47. {
  48. template <typename Sequence, typename N>
  49. struct value_at_key
  50. : extension::value_at_key_impl<typename detail::tag_of<Sequence>::type>::
  51. template apply<Sequence, N>
  52. {};
  53. }
  54. }}
  55. #endif