1 2 // Copyright Aleksey Gurtovoy 2002-2004 3 // 4 // Distributed under the Boost Software License, Version 1.0. 5 // (See accompanying file LICENSE_1_0.txt or copy at 6 // http://www.boost.org/LICENSE_1_0.txt) 7 // 8 // See http://www.boost.org/libs/mpl for documentation. 9 10 // $Id$ 11 // $Date$ 12 // $Revision$ 13 14 #include <boost/mpl/inherit.hpp> 15 #include <boost/mpl/inherit_linearly.hpp> 16 #include <boost/mpl/list.hpp> 17 18 #include <iostream> 19 20 namespace mpl = boost::mpl; 21 using namespace mpl::placeholders; 22 23 template< typename T > 24 struct tuple_field 25 { 26 typedef tuple_field type; // note the typedef 27 T field_; 28 }; 29 30 template< typename T > 31 inline field(tuple_field<T> & t)32T& field(tuple_field<T>& t) 33 { 34 return t.field_; 35 } 36 37 typedef mpl::inherit_linearly< 38 mpl::list<int,char const*,bool> 39 , mpl::inherit< _1, tuple_field<_2> > 40 >::type my_tuple; 41 42 main()43int main() 44 { 45 my_tuple t; 46 47 field<int>(t) = -1; 48 field<char const*>(t) = "text"; 49 field<bool>(t) = false; 50 51 std::cout 52 << field<int>(t) << '\n' 53 << field<char const*>(t) << '\n' 54 << field<bool>(t) << '\n' 55 ; 56 57 return 0; 58 } 59