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_linearly.hpp>
15 #include <boost/mpl/int.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 Base, typename T >
24 struct tuple_part
25 : Base
26 {
27 typedef tuple_part type; // note the typedef
28 typedef typename Base::index::next index;
29
field(tuple_part & t,index)30 friend T& field(tuple_part& t, index) { return t.field_; }
31 T field_;
32 };
33
34 struct empty_tuple
35 {
36 typedef mpl::int_<-1> index;
37 };
38
39
40 typedef mpl::inherit_linearly<
41 mpl::list<int,char const*,bool>
42 , tuple_part<_,_>
43 , empty_tuple
44 >::type my_tuple;
45
46
main()47 int main()
48 {
49 my_tuple t;
50
51 field(t, mpl::int_<0>()) = -1;
52 field(t, mpl::int_<1>()) = "text";
53 field(t, mpl::int_<2>()) = false;
54
55 std::cout
56 << field(t, mpl::int_<0>()) << '\n'
57 << field(t, mpl::int_<1>()) << '\n'
58 << field(t, mpl::int_<2>()) << '\n'
59 ;
60
61 return 0;
62 }
63