[Boost-bugs] [Boost C++ Libraries] #8407: Unclear docs for is_base_of

Subject: [Boost-bugs] [Boost C++ Libraries] #8407: Unclear docs for is_base_of
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2013-04-05 17:00:20


#8407: Unclear docs for is_base_of
----------------------------------+-----------------------------------------
 Reporter: driscoll@… | Owner: johnmaddock
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: type_traits
  Version: Boost 1.53.0 | Severity: Problem
 Keywords: |
----------------------------------+-----------------------------------------
 It isn't clear (at least to me) from
 [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] whether it evaluates to `true_type` when
 `Base` is an //direct// base class of `Derived` or //any// inheritance
 ancestor. It would be nice if this were clarified.

 (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.)

 I had to try the following program to figure out what the behavior is
 (which seems to be "`true` if `Base` is any ancestor of `Derived`"):
 {{{
 #include <boost/type_traits.hpp>
 #include <iostream>

 struct Base {};
 struct Intermediate : Base {};
 struct Derived : Intermediate {};

 template <typename Base, typename Derived>
 const char * answer(Base a, Derived b) {
     return boost::is_base_of<Base, Derived>::value ? "yes" : "no";
 }

 int main() {
     Base b;
     Intermediate i;
     Derived d;
     std::cout << "Checks:\n"
               << " Base is a base class of base [expect yes]: " <<
 answer(b, b) << "\n"
               << " Inter. is a base class of base [expect yes]: " <<
 answer(b, i) << "\n"
               << " Derived is a base class of inter. [expect yes]: " <<
 answer(i, d) << "\n"
               << " Base is a base class of derived [expect no]: " <<
 answer(d, b) << "\n"
               << "Actual answer:\n"
               << " Derived is a base class of base: " << answer(b, d) <<
 "\n";
 }
 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/8407>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:12 UTC