]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/spirit/example/qi/typeof.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / spirit / example / qi / typeof.cpp
1 /*=============================================================================
2 Copyright (c) 2001-2010 Joel de Guzman
3
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 =============================================================================*/
7 #include <boost/spirit/include/qi.hpp>
8 #include <boost/spirit/include/qi_copy.hpp>
9 #include <boost/spirit/include/support_auto.hpp>
10 #include <iostream>
11 #include <string>
12
13 ///////////////////////////////////////////////////////////////////////////////
14 // Main program
15 ///////////////////////////////////////////////////////////////////////////////
16
17 int
18 main()
19 {
20 using boost::spirit::ascii::space;
21 using boost::spirit::ascii::char_;
22 using boost::spirit::qi::parse;
23 typedef std::string::const_iterator iterator_type;
24
25 ///////////////////////////////////////////////////////////////////////////////
26 // this works for non-c++11 compilers
27 #ifdef BOOST_NO_CXX11_AUTO_DECLARATIONS
28
29 BOOST_SPIRIT_AUTO(qi, comment, "/*" >> *(char_ - "*/") >> "*/");
30
31 ///////////////////////////////////////////////////////////////////////////////
32 // but this is better for c++11 compilers with auto
33 #else
34
35 using boost::spirit::qi::copy;
36
37 auto comment = copy("/*" >> *(char_ - "*/") >> "*/");
38
39 #endif
40
41 std::string str = "/*This is a comment*/";
42 std::string::const_iterator iter = str.begin();
43 std::string::const_iterator end = str.end();
44 bool r = parse(iter, end, comment);
45
46 if (r && iter == end)
47 {
48 std::cout << "-------------------------\n";
49 std::cout << "Parsing succeeded\n";
50 std::cout << "-------------------------\n";
51 }
52 else
53 {
54 std::string rest(iter, end);
55 std::cout << "-------------------------\n";
56 std::cout << "Parsing failed\n";
57 std::cout << "stopped at: \": " << rest << "\"\n";
58 std::cout << "-------------------------\n";
59 }
60
61 return 0;
62 }
63
64