Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: downloads/boost_1_33_1/libs/mpl/example/inherit_multiply.cpp @ 12

Last change on this file since 12 was 12, checked in by landauf, 18 years ago

added boost

File size: 1.2 KB
Line 
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// $Source: /cvsroot/boost/boost/libs/mpl/example/inherit_multiply.cpp,v $
11// $Date: 2004/09/02 15:41:29 $
12// $Revision: 1.4 $
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
20namespace mpl = boost::mpl;
21using namespace mpl::placeholders;
22
23template< typename T >
24struct tuple_field
25{
26    typedef tuple_field type; // note the typedef
27    T field_;
28};
29
30template< typename T >
31inline
32T& field(tuple_field<T>& t)
33{
34    return t.field_;
35}
36
37typedef mpl::inherit_linearly<
38      mpl::list<int,char const*,bool>
39    , mpl::inherit< _1, tuple_field<_2> >
40    >::type my_tuple;
41   
42
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}
Note: See TracBrowser for help on using the repository browser.