get_prev_char.qbk 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. [#get_prev_char]
  2. [section get_prev_char]
  3. [h1 Synopsis]
  4. template <class SourcePosition>
  5. struct get_prev_char;
  6. This is a [link lazy_metafunction lazy template metafunction].
  7. [table Arguments
  8. [[Name] [Type]]
  9. [[`SourcePosition`] [[link source_position source position]]]
  10. ]
  11. [h1 Description]
  12. Returns the last character the source position was updated with. The value it
  13. returns for [link start `start`] is unspecified.
  14. [h1 Header]
  15. #include <boost/metaparse/get_prev_char.hpp>
  16. [h1 Expression semantics]
  17. For any `l`, `c` compile-time wrapped integral values and `ch` compile-time
  18. wrapped character the following are equivalent
  19. get_prev_char<source_position<l, c, ch>>::type
  20. ch::type
  21. [h1 Example]
  22. #include <boost/metaparse/get_prev_char.hpp>
  23. #include <boost/metaparse/source_position.hpp>
  24. #include <type_traits>
  25. using namespace boost::metaparse;
  26. struct returns_source_position
  27. {
  28. using type =
  29. source_position<
  30. std::integral_constant<int, 11>,
  31. std::integral_constant<int, 13>,
  32. std::integral_constant<char, 'x'>
  33. >;
  34. };
  35. static_assert(
  36. get_prev_char<
  37. source_position<
  38. std::integral_constant<int, 11>,
  39. std::integral_constant<int, 13>,
  40. std::integral_constant<char, 'x'>
  41. >
  42. >::type::value == 'x',
  43. "It should return the prev. char of a source position"
  44. );
  45. static_assert(
  46. get_prev_char<returns_source_position>::type::value == 'x',
  47. "It should support lazy evaluation"
  48. );
  49. [endsect]