|
Boost Users : |
From: Oliver.Kowalke_at_[hidden]
Date: 2005-10-27 07:01:46
no reply - so I found a solution by myself (used for the Barton &
Nackmann trick)!
cu,
Oliver
Code:
#include <iostream>
#include <cstdlib>
#include <string>
#include <boost/mpl/begin_end.hpp>
#include <boost/mpl/deref.hpp>
#include <boost/mpl/next.hpp>
#include <boost/mpl/vector.hpp>
namespace mpl = boost::mpl;
////////////////////////////////////
template<
typename B,
typename E
>
struct scattered;
template<
typename B,
typename E
>
struct scattered
:
public mpl::deref< B >::type,
public scattered<
typename mpl::next< B >::type,
E
>
{};
template< typename E >
struct scattered< E, E >
{};
////////////////////////////////////
template< typename Sequence >
struct inherit_scattered
:
public scattered<
typename mpl::begin< Sequence >::type,
typename mpl::end< Sequence >::type
>
{};
////////////////////////////////////
template< typename D >
struct F
{
std::string f()
{ return static_cast< D & >( * this).str_; }
};
template< typename D >
struct G
{
std::string g()
{ return static_cast< D & >( * this).str_; }
};
////////////////////////////////////
class A
:
public inherit_scattered<
mpl::vector<
F< A >,
G< A >
>
>
{
private:
template< typename X >
friend struct F;
template< typename X >
friend struct G;
std::string str_;
public:
A( std::string const& str)
: str_( str)
{}
};
int main( int argc, char *argv[])
{
A a("Hello World!");
std::cout << a.f() << std::endl;
std::cout << a.g() << std::endl;
return EXIT_SUCCESS;
}
>Hi,
>how is it possible to inherit from all items inside mpl::vector?
>
>template< typename V >
>class multi
>: .... // ?????
>{};
>
>typedef multi < mpl::vector< A ,B, C > > multi _t;
>multi_t m; // m has all public and protected member functions of A, B
and C
>Best Regards,
>Oliver
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net