/*============================================================================= Copyright (c) 2010 Christopher Schmidt Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) ==============================================================================*/ #include #include #include #include #include #include #include namespace fusion=boost::fusion; template struct employee { private: Name name; Age age; public: template void set_name(OtherName const& n) { name=n; } template void set_age(OtherAge const& a) { age=a; } Name& get_name() { return name; } Name const& get_name()const { return name; } Age& get_age() { return age; } Age const& get_age()const { return age; } }; namespace keys { struct name; struct age; } BOOST_FUSION_ADAPT_ASSOC_TPL_ADT( (Name)(Age), (employee) (Name)(Age), (Name&, Name const&, obj.get_name(), obj.template set_name(val), keys::name) (Age&, Age const&, obj.get_age(), obj.template set_age(val), keys::age)) int main() { typedef employee et; typedef et const etc; et e; etc& ec=e; fusion::at_key(e)="marshall mathers"; fusion::at_key(e)=37; BOOST_MPL_ASSERT(( boost::is_same< boost::fusion::result_of::value_at_key::type, std::string >)); BOOST_MPL_ASSERT(( boost::is_same< boost::fusion::result_of::value_at_key::type, boost::fusion::result_of::value_at_c::type >)); BOOST_MPL_ASSERT(( boost::is_same< boost::fusion::result_of::value_at_key::type, int >)); BOOST_MPL_ASSERT(( boost::is_same< boost::fusion::result_of::value_at_key::type, boost::fusion::result_of::value_at_c::type >)); BOOST_MPL_ASSERT(( boost::is_same< boost::fusion::result_of::at_key::type, fusion::extension::adt_attribute_proxy >)); BOOST_MPL_ASSERT(( boost::is_same< boost::fusion::result_of::at_key::type, fusion::extension::adt_attribute_proxy >)); BOOST_MPL_ASSERT(( boost::is_same< boost::fusion::result_of::at_key::type, boost::fusion::result_of::front::type >)); BOOST_MPL_ASSERT(( boost::is_same< boost::fusion::result_of::at_key::type, boost::fusion::result_of::back::type >)); BOOST_MPL_ASSERT(( boost::is_same< boost::fusion::result_of::at_key::type, fusion::extension::adt_attribute_proxy >)); BOOST_MPL_ASSERT(( boost::is_same< boost::fusion::result_of::at_key::type, fusion::extension::adt_attribute_proxy >)); BOOST_MPL_ASSERT(( boost::is_same< boost::fusion::result_of::at_key::type, boost::fusion::result_of::front::type >)); BOOST_MPL_ASSERT(( boost::is_same< boost::fusion::result_of::at_key::type, boost::fusion::result_of::back::type >)); BOOST_MPL_ASSERT(( boost::is_same< fusion::extension::adt_attribute_proxy::type, std::string& >)); BOOST_MPL_ASSERT(( boost::is_same< fusion::extension::adt_attribute_proxy::type, std::string const& >)); BOOST_MPL_ASSERT(( boost::is_same< fusion::extension::adt_attribute_proxy::type, int& >)); BOOST_MPL_ASSERT(( boost::is_same< fusion::extension::adt_attribute_proxy::type, int const& >)); { std::string& name=fusion::at_key(e); int& age=fusion::at_key(e); BOOST_TEST(name=="marshall mathers"); BOOST_TEST(age==37); BOOST_TEST(fusion::at_key(e).get()=="marshall mathers"); BOOST_TEST(fusion::at_key(e).get()==37); BOOST_TEST(fusion::front(e).get()=="marshall mathers"); BOOST_TEST(fusion::back(e).get()==37); } { std::string const& name=fusion::at_key(ec); int const& age=fusion::at_key(ec); BOOST_TEST(name=="marshall mathers"); BOOST_TEST(age==37); BOOST_TEST(fusion::at_key(ec).get()=="marshall mathers"); BOOST_TEST(fusion::at_key(ec).get()==37); BOOST_TEST(fusion::front(ec).get()=="marshall mathers"); BOOST_TEST(fusion::back(ec).get()==37); } return boost::report_errors(); }