Boost C++ Libraries: Ticket #8407: Unclear docs for is_base_of https://svn.boost.org/trac10/ticket/8407 <p> It isn't clear (at least to me) from <a href="http://www.boost.org/doc/libs/1_53_0/libs/type_traits/doc/html/boost_typetraits/reference/is_base_of.html">the documentation for is_base_of</a> whether it evaluates to <code>true_type</code> when <code>Base</code> is an <em>direct</em> base class of <code>Derived</code> or <em>any</em> inheritance ancestor. It would be nice if this were clarified. </p> <p> (I understand the first para of chapter 10 of the C++03 standard to define the term "base class" as including both direct and indirect base classes, but IMO this is surprising; myself and two nearby people I informally polled equate "base class" with "direct base class". At the suggestion of a fourth, we looked it up in the standard for the purposes of this report.) </p> <p> I had to try the following program to figure out what the behavior is (which seems to be "<code>true</code> if <code>Base</code> is any ancestor of <code>Derived</code>"): </p> <pre class="wiki">#include &lt;boost/type_traits.hpp&gt; #include &lt;iostream&gt; struct Base {}; struct Intermediate : Base {}; struct Derived : Intermediate {}; template &lt;typename Base, typename Derived&gt; const char * answer(Base a, Derived b) { return boost::is_base_of&lt;Base, Derived&gt;::value ? "yes" : "no"; } int main() { Base b; Intermediate i; Derived d; std::cout &lt;&lt; "Checks:\n" &lt;&lt; " Base is a base class of base [expect yes]: " &lt;&lt; answer(b, b) &lt;&lt; "\n" &lt;&lt; " Inter. is a base class of base [expect yes]: " &lt;&lt; answer(b, i) &lt;&lt; "\n" &lt;&lt; " Derived is a base class of inter. [expect yes]: " &lt;&lt; answer(i, d) &lt;&lt; "\n" &lt;&lt; " Base is a base class of derived [expect no]: " &lt;&lt; answer(d, b) &lt;&lt; "\n" &lt;&lt; "Actual answer:\n" &lt;&lt; " Derived is a base class of base: " &lt;&lt; answer(b, d) &lt;&lt; "\n"; } </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/8407 Trac 1.4.3 John Maddock Thu, 13 Jun 2013 16:06:31 GMT <link>https://svn.boost.org/trac10/ticket/8407#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/8407#comment:1</guid> <description> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/84761" title="Clarify that base classes include indirect ancestors. Refs #8407.">[84761]</a>) Clarify that base classes include indirect ancestors. Refs <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/8407" title="#8407: Bugs: Unclear docs for is_base_of (closed: fixed)">#8407</a>. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>John Maddock</dc:creator> <pubDate>Thu, 13 Jun 2013 16:09:13 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/8407#comment:2 https://svn.boost.org/trac10/ticket/8407#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/84762" title="Clarify that base classes include indirect ancestors. Fixes #8407.">[84762]</a>) Clarify that base classes include indirect ancestors. Fixes <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/8407" title="#8407: Bugs: Unclear docs for is_base_of (closed: fixed)">#8407</a>. </p> Ticket