What is the equivalent to boost::spirit::qi::matches in boost::spirit::karma? For example I want to generate a literal "array" only if a boolean flag is set true.
Asked
Active
Viewed 106 times
2
-
1http://stackoverflow.com/questions/25502777/generate-string-if-boolean-attribute-is-true-karma-counterpart-to-qimatches – llonesmiz May 14 '15 at 06:19
-
@cv_and_he hehe. Completely forgot about that one :) – sehe May 18 '15 at 12:24
1 Answers
2
Use the specified value form of bool_
to consume the attribute only if it matches the supplied value:
#include <boost/spirit/include/karma.hpp>
namespace karma = boost::spirit::karma;
int main() {
using namespace karma;
for (int i = 0; i < 10; ++i)
{
bool b = (0 == i%3);
std::cout << format_delimited(
(omit[bool_(true)] << "array" | omit[bool_(false) << "vector"]),
';',
b
) << "\n";
}
}
Prints
array;
array;
array;
array;

sehe
- 374,641
- 47
- 450
- 633