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