tuple_traits.hpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /*=============================================================================
  2. Copyright (c) 2001-2014 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(BOOST_SPIRIT_X3_TUPLE_TRAITS_JANUARY_2012_1132PM)
  7. #define BOOST_SPIRIT_X3_TUPLE_TRAITS_JANUARY_2012_1132PM
  8. #include <boost/fusion/include/is_sequence.hpp>
  9. #include <boost/fusion/include/is_view.hpp>
  10. #include <boost/fusion/include/size.hpp>
  11. #include <boost/mpl/bool.hpp>
  12. #include <boost/mpl/and.hpp>
  13. namespace boost { namespace spirit { namespace x3 { namespace traits
  14. {
  15. template <typename A, typename B>
  16. struct has_same_size
  17. : mpl::bool_<(
  18. fusion::result_of::size<A>::value ==
  19. fusion::result_of::size<B>::value
  20. )>
  21. {};
  22. template <typename T, std::size_t N>
  23. struct has_size
  24. : mpl::bool_<(fusion::result_of::size<T>::value == N)>
  25. {};
  26. template <typename A, typename B>
  27. struct is_same_size_sequence
  28. : mpl::and_<
  29. fusion::traits::is_sequence<A>
  30. , fusion::traits::is_sequence<B>
  31. , has_same_size<A, B>
  32. >
  33. {};
  34. template <typename Seq>
  35. struct is_size_one_sequence
  36. : mpl::and_<
  37. fusion::traits::is_sequence<Seq>
  38. , has_size<Seq, 1>
  39. >
  40. {};
  41. template <typename View>
  42. struct is_size_one_view
  43. : mpl::and_<
  44. fusion::traits::is_view<View>
  45. , has_size<View, 1>
  46. >
  47. {};
  48. }}}}
  49. #endif