confix.cpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. // Copyright (c) 2001-2010 Hartmut Kaiser
  2. //
  3. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. // The purpose of this example is to demonstrate different use cases for the
  6. // confix generator.
  7. #include <iostream>
  8. #include <string>
  9. #include <vector>
  10. //[karma_confix_includes
  11. #include <boost/spirit/include/karma.hpp>
  12. #include <boost/spirit/repository/include/karma_confix.hpp>
  13. //]
  14. //[karma_confix_namespace
  15. using namespace boost::spirit;
  16. using namespace boost::spirit::ascii;
  17. using boost::spirit::repository::confix;
  18. //]
  19. int main()
  20. {
  21. //[karma_confix_cpp_comment
  22. // C++ comment
  23. std::cout <<
  24. karma::format_delimited(
  25. confix("//", eol)[string], // format description
  26. space, // delimiter
  27. "This is a comment" // data
  28. ) << std::endl;
  29. //]
  30. //[karma_confix_c_comment
  31. // C comment
  32. std::cout <<
  33. karma::format_delimited(
  34. confix("/*", "*/")[string], // format description
  35. space, // delimiter
  36. "This is a comment" // data
  37. ) << std::endl;
  38. //]
  39. //[karma_confix_function
  40. // Generate a function call with an arbitrary parameter list
  41. std::vector<std::string> parameters;
  42. parameters.push_back("par1");
  43. parameters.push_back("par2");
  44. parameters.push_back("par3");
  45. std::cout <<
  46. karma::format(
  47. string << confix('(', ')')[string % ','], // format description
  48. "func", // function name
  49. parameters // parameter names
  50. ) << std::endl;
  51. //]
  52. return 0;
  53. }