next_line.qbk 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. [#next_line]
  2. [section next_line]
  3. [h1 Synopsis]
  4. template <class SourcePosition, class Ch>
  5. struct next_line;
  6. This is a [link lazy_metafunction lazy template metafunction].
  7. [table Arguments
  8. [[Name] [Type]]
  9. [[`SourcePosition`] [[link source_position source position]]]
  10. [[`Ch`] [[link boxed_value boxed] character value. The character `SourcePosition` points to in the input.]]
  11. ]
  12. [h1 Description]
  13. Returns a new source position, pointing to the beginning of the next line.
  14. [h1 Header]
  15. #include <boost/metaparse/next_line.hpp>
  16. [h1 Expression semantics]
  17. For any `s` source position and `c` wrapped character the following are
  18. equivalent
  19. get_col<next_line<s, c>>::type
  20. boost::mpl::int_<1>
  21. get_line<next_line<s, c>>
  22. boost::mpl::plus<get_line<s>::type, boost::mpl::int_<1>>
  23. get_prev_char<next_line<s, c>>::type
  24. c
  25. [h1 Example]
  26. #include <boost/metaparse/next_line.hpp>
  27. #include <boost/metaparse/source_position.hpp>
  28. #include <boost/metaparse/get_col.hpp>
  29. #include <boost/metaparse/get_line.hpp>
  30. #include <boost/metaparse/get_prev_char.hpp>
  31. #include <type_traits>
  32. using namespace boost::metaparse;
  33. struct returns_source_position
  34. {
  35. using type =
  36. source_position<
  37. std::integral_constant<int, 11>,
  38. std::integral_constant<int, 13>,
  39. std::integral_constant<char, 'a'>
  40. >;
  41. };
  42. struct returns_char
  43. {
  44. using type = std::integral_constant<char, '\n'>;
  45. };
  46. static_assert(
  47. get_col<
  48. next_line<
  49. source_position<
  50. std::integral_constant<int, 11>,
  51. std::integral_constant<int, 13>,
  52. std::integral_constant<char, 'a'>
  53. >,
  54. std::integral_constant<char, '\n'>
  55. >
  56. >::type::value == 1,
  57. "it should set the column to 1"
  58. );
  59. static_assert(
  60. get_line<
  61. next_line<
  62. source_position<
  63. std::integral_constant<int, 11>,
  64. std::integral_constant<int, 13>,
  65. std::integral_constant<char, 'a'>
  66. >,
  67. std::integral_constant<char, '\n'>
  68. >
  69. >::type::value == 12,
  70. "it should increase the line component of the source position"
  71. );
  72. static_assert(
  73. get_prev_char<
  74. next_line<
  75. source_position<
  76. std::integral_constant<int, 11>,
  77. std::integral_constant<int, 13>,
  78. std::integral_constant<char, 'a'>
  79. >,
  80. std::integral_constant<char, '\n'>
  81. >
  82. >::type::value == '\n',
  83. "it should update the prev char component of the source position"
  84. );
  85. static_assert(
  86. get_col<next_line<returns_source_position, returns_char>>::type::value == 1,
  87. "it should support lazy evaluation"
  88. );
  89. [endsect]