| 1 | #include <boost/fusion/adapted/struct/adapt_struct.hpp>
|
|---|
| 2 | #include <boost/fusion/container/vector/vector.hpp>
|
|---|
| 3 | #include <boost/fusion/algorithm/query/find.hpp>
|
|---|
| 4 |
|
|---|
| 5 | #include <boost/type_traits.hpp>
|
|---|
| 6 |
|
|---|
| 7 | #include <string>
|
|---|
| 8 | #include <iostream>
|
|---|
| 9 |
|
|---|
| 10 | namespace b = boost;
|
|---|
| 11 | namespace bf = boost::fusion;
|
|---|
| 12 |
|
|---|
| 13 | namespace demo
|
|---|
| 14 | {
|
|---|
| 15 | struct employee
|
|---|
| 16 | {
|
|---|
| 17 | std::string name;
|
|---|
| 18 | int age;
|
|---|
| 19 | };
|
|---|
| 20 | }
|
|---|
| 21 |
|
|---|
| 22 | // demo::employee is now a Fusion sequence
|
|---|
| 23 | BOOST_FUSION_ADAPT_STRUCT(
|
|---|
| 24 | demo::employee,
|
|---|
| 25 | (std::string, name)
|
|---|
| 26 | (int, age))
|
|---|
| 27 |
|
|---|
| 28 | int main(void)
|
|---|
| 29 | {
|
|---|
| 30 | typedef bf::vector<int,float> V1;
|
|---|
| 31 |
|
|---|
| 32 | // Find against non-const V1
|
|---|
| 33 | V1 v1(1,2.0);
|
|---|
| 34 |
|
|---|
| 35 | BOOST_MPL_ASSERT_NOT(( b::is_same<bf::result_of::find<V1,int>::type,bf::result_of::end<V1>::type> ));
|
|---|
| 36 |
|
|---|
| 37 | assert(*bf::find<int>(v1) == 1);
|
|---|
| 38 |
|
|---|
| 39 |
|
|---|
| 40 | // Find against const V1
|
|---|
| 41 | const V1 const_v1(3,4.0);
|
|---|
| 42 |
|
|---|
| 43 | BOOST_MPL_ASSERT_NOT(( b::is_same<bf::result_of::find<const V1,int>::type,bf::result_of::end<const V1>::type> ));
|
|---|
| 44 |
|
|---|
| 45 | assert(*bf::find<int>(const_v1) == 3);
|
|---|
| 46 |
|
|---|
| 47 | // Find against non-const employee
|
|---|
| 48 | demo::employee e1 = {"Foo",18};
|
|---|
| 49 |
|
|---|
| 50 | BOOST_MPL_ASSERT_NOT(( b::is_same<bf::result_of::find<demo::employee,int>::type,bf::result_of::end<demo::employee>::type> ));
|
|---|
| 51 |
|
|---|
| 52 | assert(*bf::find<int>(e1) == 18);
|
|---|
| 53 |
|
|---|
| 54 | // Find against const employee
|
|---|
| 55 | const demo::employee const_e1 = {"Bar",21};
|
|---|
| 56 |
|
|---|
| 57 | #if 0
|
|---|
| 58 | BOOST_MPL_ASSERT_NOT(( b::is_same<bf::result_of::find<const demo::employee,int>::type,bf::result_of::end<const demo::employee>::type> ));
|
|---|
| 59 |
|
|---|
| 60 | assert(*bf::find<int>(const_e1) == 21);
|
|---|
| 61 | #else
|
|---|
| 62 | // note that the find key is a const int
|
|---|
| 63 | BOOST_MPL_ASSERT_NOT(( b::is_same<bf::result_of::find<const demo::employee,const int>::type,bf::result_of::end<const demo::employee>::type> ));
|
|---|
| 64 |
|
|---|
| 65 | assert(*bf::find<const int>(const_e1) == 21);
|
|---|
| 66 | #endif
|
|---|
| 67 |
|
|---|
| 68 | return 0;
|
|---|
| 69 | }
|
|---|