at_impl.hpp 1.8 KB

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