| 1 | #include <iostream>
|
|---|
| 2 | #include <string>
|
|---|
| 3 |
|
|---|
| 4 | #include <boost/spirit/include/support_utree.hpp>
|
|---|
| 5 |
|
|---|
| 6 | int main(int ac, char** av)
|
|---|
| 7 | {
|
|---|
| 8 | boost::spirit::utree u;
|
|---|
| 9 | std::string test("test");
|
|---|
| 10 |
|
|---|
| 11 | u = test;
|
|---|
| 12 |
|
|---|
| 13 | std::cout
|
|---|
| 14 | << "u = " << u
|
|---|
| 15 | << ", " << u.which()
|
|---|
| 16 | << std::endl
|
|---|
| 17 | ;
|
|---|
| 18 |
|
|---|
| 19 |
|
|---|
| 20 | // 1. Using range, OK
|
|---|
| 21 | boost::spirit::utf8_string_range_type srange =
|
|---|
| 22 | u.get<boost::spirit::utf8_string_range_type>();
|
|---|
| 23 |
|
|---|
| 24 | std::string s1(srange.begin(), srange.end());
|
|---|
| 25 | std::cout << "s1 = " << s1 << std::endl;
|
|---|
| 26 |
|
|---|
| 27 | // 2. Using spirit string, FAIL --> std::bad_cast
|
|---|
| 28 | std::string s2 = u.get<boost::spirit::utf8_string_type>();
|
|---|
| 29 | std::cout << "s2 = " << s2 << std::endl;
|
|---|
| 30 |
|
|---|
| 31 | // 3. Using std::string, FAIL --> std::bad_cast
|
|---|
| 32 | std::string s3 = u.get<std::string>();
|
|---|
| 33 | std::cout << "s3 = " << s3 << std::endl;
|
|---|
| 34 |
|
|---|
| 35 | return 0;
|
|---|
| 36 | }
|
|---|