9
3

at_key_impl.hpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*=============================================================================
  2. Copyright (c) 2001-2011 Joel de Guzman
  3. Copyright (c) 2005-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_IMPL_20060223_2017)
  8. #define BOOST_FUSION_AT_KEY_IMPL_20060223_2017
  9. #include <string>
  10. #include <boost/mpl/if.hpp>
  11. #include <boost/type_traits/is_const.hpp>
  12. namespace fields
  13. {
  14. struct name;
  15. struct age;
  16. }
  17. namespace example
  18. {
  19. struct example_sequence_tag;
  20. }
  21. namespace boost { namespace fusion {
  22. namespace extension
  23. {
  24. template<typename Tag>
  25. struct at_key_impl;
  26. template<>
  27. struct at_key_impl<example::example_sequence_tag>
  28. {
  29. template<typename Sequence, typename Key>
  30. struct apply;
  31. template<typename Sequence>
  32. struct apply<Sequence, fields::name>
  33. {
  34. typedef typename mpl::if_<
  35. is_const<Sequence>,
  36. std::string const&,
  37. std::string&>::type type;
  38. static type
  39. call(Sequence& seq)
  40. {
  41. return seq.name;
  42. };
  43. };
  44. template<typename Sequence>
  45. struct apply<Sequence, fields::age>
  46. {
  47. typedef typename mpl::if_<
  48. is_const<Sequence>,
  49. int const&,
  50. int&>::type type;
  51. static type
  52. call(Sequence& seq)
  53. {
  54. return seq.age;
  55. };
  56. };
  57. };
  58. }
  59. }}
  60. #endif