BOOST_METAPARSE_STRING.qbk 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. [#BOOST_METAPARSE_STRING]
  2. [section BOOST_METAPARSE_STRING]
  3. [h1 Synopsis]
  4. #define BOOST_METAPARSE_STRING(s) \
  5. // unspecified
  6. This is a macro.
  7. [table Arguments
  8. [[Name] [Type]]
  9. [[`s`] [string literal]]
  10. ]
  11. [h1 Description]
  12. Macro for defining [link string `string`] values. `s` is expected to be a
  13. string literal. The macro requires C++11.
  14. The maximal length of the string is limited. This limit is defined by the
  15. `BOOST_METAPARSE_LIMIT_STRING_SIZE` macro.
  16. On platforms where `BOOST_METAPARSE_STRING` is not supported, the `string.hpp`
  17. header defines the `BOOST_METAPARSE_V1_CONFIG_NO_BOOST_METAPARSE_STRING` macro.
  18. Defining this macro before including the header disables the
  19. `BOOST_METAPARSE_STRING` macro.
  20. The upper limit for the maximum length, which can be used is 2048. The
  21. implementation of the `BOOST_METAPARSE_STRING` macro is generated using
  22. `tools/string_headers.py` and can be regenerated to extend this upper limit.
  23. Note that for Oracle Developer Studio the string length limit is 127.
  24. Metaparse supports changing the string length limit within a compilation unit.
  25. To change the length limit, redefine the `BOOST_METAPARSE_LIMIT_STRING_SIZE`
  26. macro.
  27. You can find benchmarks of this macro
  28. [link BOOST_METAPARSE_STRING_benchmark here].
  29. [h1 Header]
  30. #include <boost/metaparse/string.hpp>
  31. [h1 Expression semantics]
  32. The semantics of this macro is demonstrated by an example. The following
  33. BOOST_METAPARSE_STRING("hello")
  34. is equivalent to
  35. string<'h','e','l','l','o'>
  36. [h1 Example]
  37. #define BOOST_METAPARSE_LIMIT_STRING_SIZE 8
  38. #include <boost/metaparse/string.hpp>
  39. #include <type_traits>
  40. using namespace boost::metaparse;
  41. using hello1 = string<'H','e','l','l','o'>;
  42. using hello2 = BOOST_METAPARSE_STRING("Hello");
  43. static_assert(
  44. std::is_same<
  45. string<'H', 'e', 'l', 'l', 'o'>,
  46. BOOST_METAPARSE_STRING("Hello")
  47. >::type::value,
  48. "The type generated by the macro should be identical to the hand-crafted one."
  49. );
  50. #undef BOOST_METAPARSE_LIMIT_STRING_SIZE
  51. #define BOOST_METAPARSE_LIMIT_STRING_SIZE 32
  52. static_assert(
  53. std::is_same<
  54. string<
  55. 'A', ' ', 'l', 'o', 'n', 'g', 'e', 'r',
  56. ' ', 's', 't', 'r', 'i', 'n', 'g'
  57. >,
  58. BOOST_METAPARSE_STRING("A longer string")
  59. >::type::value,
  60. "The type generated by the macro should be identical to the hand-crafted one."
  61. );
  62. [endsect]