[ create a new paste ] login | about

Link: http://codepad.org/u5Lf5yok    [ raw code | output | fork ]

C++, pasted on Jan 3:
#include <iostream>

struct TEvent
{
};

template< typename PDerived00 >
struct TBase
{
 public:
  void OnEvent( TEvent const * fEvent )
  {
   std::cout << "TBase::OnEvent" << std::endl;
   if( typeid(PDerived00) != typeid(TBase) )
   {
    static_cast< PDerived00 * > ( this )->OnEventImpl( fEvent );

    if( typeid(typename PDerived00::TDerived) != typeid(PDerived00) )
    {
     static_cast< typename PDerived00::TDerived * > ( this )->OnEventImpl( fEvent );

     if( typeid(typename PDerived00::TDerived::TDerived) != typeid(typename PDerived00::TDerived) )
     {
      static_cast< typename PDerived00::TDerived::TDerived * > ( this )->OnEventImpl( fEvent );

      if( typeid(typename PDerived00::TDerived::TDerived::TDerived) != typeid(typename PDerived00::TDerived::TDerived) )
      {
       static_cast< typename PDerived00::TDerived::TDerived::TDerived * > ( this )->OnEventImpl( fEvent );

       if( typeid(typename PDerived00::TDerived::TDerived::TDerived::TDerived) != typeid(typename PDerived00::TDerived::TDerived::TDerived) )
       {
	static_cast< typename PDerived00::TDerived::TDerived::TDerived::TDerived * > ( this )->OnEventImpl( fEvent );

	if( typeid(typename PDerived00::TDerived::TDerived::TDerived::TDerived::TDerived)
	  != typeid(typename PDerived00::TDerived::TDerived::TDerived::TDerived) )
	{
	 static_cast< typename PDerived00::TDerived::TDerived::TDerived::TDerived::TDerived * > ( this )->OnEventImpl( fEvent );

	 if( typeid(typename PDerived00::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived)
	   != typeid(typename PDerived00::TDerived::TDerived::TDerived::TDerived::TDerived) )
	 {
	  static_cast< typename PDerived00::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived * > ( this )->OnEventImpl( fEvent );

	  if( typeid(typename PDerived00::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived)
	    != typeid(typename PDerived00::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived) )
	  {
	   static_cast< typename PDerived00::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived * > ( this )->OnEventImpl( fEvent );

	   if( typeid(typename PDerived00::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived)
	     != typeid(typename PDerived00::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived) )
	   {
	    static_cast< typename PDerived00::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived * > ( this )->OnEventImpl( fEvent );

	    if( typeid(typename PDerived00::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived)
	      != typeid(typename PDerived00::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived) )
	    {
	     static_cast< typename PDerived00::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived * > ( this )->OnEventImpl(
																				   fEvent );

	     if( typeid(typename PDerived00::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived)
	       != typeid(typename PDerived00::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived) )
	     {
	      static_cast< typename PDerived00::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived * > ( this )->OnEventImpl(
																					      fEvent );

	      if( typeid(typename PDerived00::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived)
		!= typeid(typename PDerived00::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived) )
	      {
	       static_cast< typename PDerived00::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived * > ( this )->OnEventImpl(
																							 fEvent );

	       if( typeid(typename PDerived00::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived)
		 != typeid(typename PDerived00::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived) )
	       {
		static_cast< typename PDerived00::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived::TDerived * > ( this )->OnEventImpl(
																								    fEvent );
	       }
	      }
	     }
	    }
	   }
	  }
	 }
	}
       }
      }
     }
    }
   }
  }
};

template< typename PDerived >
struct TDerived00 : public TBase< TDerived00< PDerived > >
{
  friend struct TBase< TDerived00 > ;

  typedef PDerived TDerived;
 private:
  void OnEventImpl( TEvent const * )
  {
   std::cout << "TDerived00::OnEventImpl" << std::endl;
  }
};

template< typename PDerived >
struct TDerived01 : public TDerived00< TDerived01< PDerived > >
{
  friend struct TBase< TDerived00< TDerived01< PDerived > > > ;

  typedef PDerived TDerived;
 private:
  void OnEventImpl( TEvent const * )
  {
   std::cout << "TDerived01::OnEventImpl" << std::endl;
  }
};

template< typename PDerived >
struct TDerived02 : public TDerived01< TDerived02< PDerived > >
{
  friend struct TBase< TDerived00< TDerived01< TDerived02< PDerived > > > > ;

  typedef PDerived TDerived;
 private:
  void OnEventImpl( TEvent const * )
  {
   std::cout << "TDerived02::OnEventImpl" << std::endl;
  }
};
template< typename PDerived >
struct TDerived03 : public TDerived02< TDerived03< PDerived > >
{
  friend struct TBase< TDerived00< TDerived01< TDerived02< TDerived03< PDerived > > > > > ;

  typedef PDerived TDerived;
 private:
  void OnEventImpl( TEvent const * )
  {
   std::cout << "TDerived03::OnEventImpl" << std::endl;
  }
};

struct TDerived04 : public TDerived03< TDerived04 >
{
  friend struct TBase< TDerived00< TDerived01< TDerived02< TDerived03< TDerived04 > > > > > ;


 private:
  void OnEventImpl( TEvent const * )
  {
   std::cout << "TDerived04::OnEventImpl" << std::endl;
  }
};

int main( void )
{
 TDerived04 lD4;

 lD4.OnEvent( 0 );
 return ( 0 );
}


Output:
1
2
3
4
5
6
TBase::OnEvent
TDerived00::OnEventImpl
TDerived01::OnEventImpl
TDerived02::OnEventImpl
TDerived03::OnEventImpl
TDerived04::OnEventImpl


Create a new paste based on this one


Comments: