| 1 | /*=============================================================================
|
|---|
| 2 | Copyright (c) 2011 Michael Caisse
|
|---|
| 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 <iostream>
|
|---|
| 8 | #include <boost/detail/lightweight_test.hpp>
|
|---|
| 9 | #include <boost/spirit/include/phoenix_core.hpp>
|
|---|
| 10 | #include <boost/fusion/include/adapt_assoc_struct.hpp>
|
|---|
| 11 | #include <boost/spirit/home/phoenix/fusion/at_key.hpp>
|
|---|
| 12 |
|
|---|
| 13 | namespace phoenix = boost::phoenix;
|
|---|
| 14 | using phoenix::arg_names::arg1;
|
|---|
| 15 |
|
|---|
| 16 | namespace test {
|
|---|
| 17 | struct foo
|
|---|
| 18 | {
|
|---|
| 19 | int x;
|
|---|
| 20 | char y;
|
|---|
| 21 | int z;
|
|---|
| 22 | };
|
|---|
| 23 |
|
|---|
| 24 | namespace key
|
|---|
| 25 | {
|
|---|
| 26 | struct x;
|
|---|
| 27 | struct y;
|
|---|
| 28 | struct z;
|
|---|
| 29 | }
|
|---|
| 30 | }
|
|---|
| 31 |
|
|---|
| 32 |
|
|---|
| 33 | BOOST_FUSION_ADAPT_ASSOC_STRUCT(
|
|---|
| 34 | test::foo,
|
|---|
| 35 | (int, x, test::key::x)
|
|---|
| 36 | (char, y, test::key::y)
|
|---|
| 37 | (int, z, test::key::z)
|
|---|
| 38 | )
|
|---|
| 39 |
|
|---|
| 40 | int main()
|
|---|
| 41 | {
|
|---|
| 42 | test::foo bar;
|
|---|
| 43 | bar.x = 42;
|
|---|
| 44 | bar.y = 'z';
|
|---|
| 45 | bar.z = 8;
|
|---|
| 46 |
|
|---|
| 47 | BOOST_TEST( phoenix::at_key<test::key::x>(arg1)(bar) == 42 );
|
|---|
| 48 | BOOST_TEST( phoenix::at_key<test::key::y>(arg1)(bar) == 'z' );
|
|---|
| 49 | BOOST_TEST( phoenix::at_key<test::key::z>(arg1)(bar) == 8 );
|
|---|
| 50 |
|
|---|
| 51 | return boost::report_errors();
|
|---|
| 52 | }
|
|---|