You can use std::is_base_of to check if a class inherits from some base class, but how do I know if a class doesn't directly inherit from that class (i.e inherits indirectly from that class)?
            Asked
            
        
        
            Active
            
        
            Viewed 294 times
        
    4
            
            
        
        Kijewski
        
- 25,517
 - 12
 - 101
 - 143
 
        template boy
        
- 10,230
 - 8
 - 61
 - 97
 
- 
                    Are you saying that if `Derived1` inherits from `Base`, and `Derived2` inherits from `Derived1`, you want something that returns `false` given `Derived1` and `Derived2` but returns `true` given `Base` and `Derived2`? – R Sahu Oct 17 '14 at 19:08
 - 
                    @RSahu Yes. And I am open to C++11 solutions if they are possible. The answer in the duplicate is good too. – template boy Oct 17 '14 at 19:08
 - 
                    This is **not** a duplicate of the other question. If anything the opposite. BTW, `is_base_of` does not only detect direct bases, IIRC – David Rodríguez - dribeas Oct 17 '14 at 20:31
 - 
                    1[`std::is_convertible
`](http://en.cppreference.com/w/cpp/types/is_convertible) is not enough I guess? – Kijewski Oct 17 '14 at 20:47 - 
                    [N2965](http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2009/n2965.html) introduces the `bases` and `direct_bases` metafunctions ([discussed before](http://stackoverflow.com/q/18435001/33732)), which would make your goal pretty easy to implement. [Support apparently already exists in GCC.](http://stackoverflow.com/a/16262354/33732) – Rob Kennedy Oct 17 '14 at 21:08