title: How to find, from which Types is object composed of?
body: <p>ok, yesterday I posted almost identical question <a href="https://stackoverflow.com/questions/7000892/how-to-find-from-which-template-layers-is-object-composed-of">here</a>
  , but I wasn't able to modify the answer(working) to my needs... I did not want to mess the other topic, so I have started new one.</p>
  
  <p>So, I have 2 (actually about 15) structs, which can composed an object</p>
  
  <pre><code>class MyBase{};
  
  template &lt;typename Super, typename T1, typename T2&gt; 
  struct A : public Super 
  {
      void doStuffA() { cout&lt;&lt;"doing something in A"; }
  };
  
  template &lt;typename Super, typename T1, typename T2&gt; 
  struct B : public Super 
  {
      void doStuffB() { cout&lt;&lt;"doing something in B"; }
  };
  </code></pre>
  
  <p>then I have:</p>
  
  <pre><code>template &lt;typename ComposedType, typename T1, typename T2&gt;
  class Combined
  {
      ComposedType m_cT;
  public:
      Combined(const ComposedType &amp; c) : m_cT(c) { }
  
      typedef A&lt;null, T1, T2&gt; anull;
      typedef B&lt;null, T1, T2&gt; bnull;
  
      void update()
      {
          typedef typename split&lt;ComposedType&gt;::Ct Ct;
          typedef typename split&lt;ComposedType&gt;::At At;
  
          //this I want 
          if( composed of A ) 
              m_cT.doStuffA();
  
          if( composed of B ) 
              m_cT.doStuffB();
      }
  };
  </code></pre>
  
  <p>and I want to use it like:</p>
  
  <pre><code>int main()
  {
      typedef A&lt;B&lt;MyBase,int,int&gt;,int,int&gt; ComposedType1;
      typedef B&lt;MyBase,int,int&gt; ComposedType2;
  
      ComposedType1 ct1;
      ComposedType2 ct2;
  
      Combined&lt;ComposedType1, int, int&gt; cb1(ct1);
      cb1.update();
  
      Combined&lt;ComposedType2, int, int&gt; cb2(ct2);
      cb2.update();
  }
  </code></pre>
  
  <p>(ints are just for example purposes)</p>
  
  <p>So I have some template magic:</p>
  
  <pre><code>struct null{};
  
  template&lt;typename&gt; 
  struct split
  {
      typedef null Ct;
      typedef null At;
  };
  
  template&lt;template&lt;typename&gt; class C, typename T&gt; 
  struct split&lt;C&lt;T&gt; &gt;
  {
      typedef C&lt;null&gt; Ct; //class template 
      typedef T      At;  //argument type
  };
  
  template&lt;template&lt;typename&gt; class C&gt; 
  struct split&lt;C&lt;MyBase&gt; &gt;
  {
      typedef C&lt;null&gt; Ct; //class template 
      typedef MyBase   At;  //argument type
  };
  </code></pre>
  
  <p>but I can not make it works :(</p>
  
  <p>I know there is a lot of code, but this is actually minimal example... I have posted this code to <a href="http://ideone.com/TXRTe" rel="nofollow noreferrer">ideone</a>, to make it better for reading.</p>
  
  <p>Thank you!</p>
  
  <p><strong>EDIT:</strong> (to ask questions in comments)</p>
  
  <p>I am building system for AI and want to solve as much thing in compile
  time as I can. In this case, I am building system for movement behavior.
   My code supply many types of behavior like "Go to point", "Evade from",
   "Avoid obstacles" etc. This behaviors are in example above 
  mentioned as A a, B. Each of this behavior has method like "performBehavior"
  and its return type can be combined with other "performBehavior".</p>
  
  <p>So I want to put together specific behavior at compile time. eg. just A or A+C+D+F etc...</p>
  
  <p>and then in my update do something like: </p>
  
  <p>if behavior is consisted of "Go to point", than "performBehaviorGoTo"</p>
  
  <p>if behavior is consisted of "Evade from", than "performBehaviorEvade"</p>
  
  <p>...</p>
  
  <p>this is very very short explanation, but hope I have made my point </p>