How do std::is_base_of and std::derived_from differ for private or ambiguous inheritance?
Show answer and explanation
For class types, std::is_base_of reports whether Base is a base-class subobject of Derived even when the inheritance is private, protected, or ambiguous. The C++20 std::derived_from concept additionally requires a valid implicit conversion from a cv-qualified Derived pointer to the corresponding Base pointer, so it models public, unambiguous inheritance and substitutability more closely. Both treat a class as related to itself, but neither proves that a derived type obeys the semantic contract of its base; that remains a design obligation.
For class types, std::is_base_of reports whether Base is a base-class subobject of Derived even when the inheritance is private, protected, or ambiguous. The C++20 std::derived_from concept additionally requires a valid implicit conversion from a cv-qualified Derived pointer to the corresponding Base pointer, so it models public, unambiguous inheritance and substitutability more closely. Both treat a class as related to itself, but neither proves that a derived type obeys the semantic contract of its base; that remains a design obligation.
Connect the conclusion directly to the type, lifetime, ownership, overload-resolution rule, or library contract present in the question. State implementation dependence or a violated precondition explicitly instead of merely guessing output.