accept.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright Abel Sinkovics (abel@sinkovics.hu) 2014.
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. #include <boost/metaparse/accept.hpp>
  6. #include <boost/metaparse/start.hpp>
  7. #include <boost/metaparse/string.hpp>
  8. #include <boost/metaparse/get_result.hpp>
  9. #include <boost/metaparse/get_position.hpp>
  10. #include <boost/metaparse/get_remaining.hpp>
  11. #include <boost/mpl/assert.hpp>
  12. #include <boost/type_traits.hpp>
  13. #include "test_case.hpp"
  14. namespace
  15. {
  16. template <class T>
  17. struct returns
  18. {
  19. typedef T type;
  20. };
  21. template <class T>
  22. struct gets_foo
  23. {
  24. typedef typename T::foo type;
  25. };
  26. }
  27. BOOST_METAPARSE_TEST_CASE(accept)
  28. {
  29. using boost::metaparse::accept;
  30. using boost::metaparse::start;
  31. using boost::metaparse::string;
  32. using boost::metaparse::get_result;
  33. using boost::metaparse::get_position;
  34. using boost::metaparse::get_remaining;
  35. using boost::is_same;
  36. typedef string<'H','e','l','l','o'> s;
  37. // test_accept_is_metaprogramming_value
  38. BOOST_MPL_ASSERT((
  39. is_same<accept<int, s, start>, accept<int, s, start>::type>
  40. ));
  41. // test_accept_is_not_lazy
  42. BOOST_MPL_ASSERT((
  43. is_same<
  44. accept<gets_foo<int>, s, start>,
  45. accept<gets_foo<int>, returns<s>, returns<start> >::type
  46. >
  47. ));
  48. // test_get_result_of_accept
  49. BOOST_MPL_ASSERT((is_same<int, get_result<accept<int, s, start> >::type>));
  50. // test_get_remaining_of_accept
  51. BOOST_MPL_ASSERT((is_same<s, get_remaining<accept<int, s, start> >::type>));
  52. // test_get_position_of_accept
  53. BOOST_MPL_ASSERT((
  54. is_same<start, get_position<accept<int, s, start> >::type>
  55. ));
  56. }