• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
6 //  The purpose of this example is to demonstrate different use cases for the
7 //  confix generator.
8 
9 #include <iostream>
10 #include <string>
11 #include <vector>
12 
13 //[karma_confix_includes
14 #include <boost/spirit/include/karma.hpp>
15 #include <boost/spirit/repository/include/karma_confix.hpp>
16 //]
17 
18 //[karma_confix_namespace
19 using namespace boost::spirit;
20 using namespace boost::spirit::ascii;
21 using boost::spirit::repository::confix;
22 //]
23 
main()24 int main()
25 {
26 //[karma_confix_cpp_comment
27     // C++ comment
28     std::cout <<
29         karma::format_delimited(
30             confix("//", eol)[string],            // format description
31             space,                                // delimiter
32             "This is a comment"                   // data
33         ) << std::endl;
34 //]
35 
36 //[karma_confix_c_comment
37     // C comment
38     std::cout <<
39         karma::format_delimited(
40             confix("/*", "*/")[string],           // format description
41             space,                                // delimiter
42             "This is a comment"                   // data
43         ) << std::endl;
44 //]
45 
46 //[karma_confix_function
47     // Generate a function call with an arbitrary parameter list
48     std::vector<std::string> parameters;
49     parameters.push_back("par1");
50     parameters.push_back("par2");
51     parameters.push_back("par3");
52 
53     std::cout <<
54         karma::format(
55             string << confix('(', ')')[string % ','],   // format description
56             "func",                                     // function name
57             parameters                                  // parameter names
58         ) << std::endl;
59 //]
60 
61     return 0;
62 }
63 
64