This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of NAD status.
849. missing type traits to compute root class and derived class of types in a class hierachySection: 21.3.9.7 [meta.trans.other] Status: NAD Submitter: Thorsten Ottosen Opened: 2008-06-05 Last modified: 2016-01-28
Priority: Not Prioritized
View all other issues in [meta.trans.other].
View all issues with NAD status.
Discussion:
The type traits library contains various traits to dealt with polymorphic types, e.g. std::has_virtual_destructor
, std::is_polymorphic
and std::is_base_of
. However, there is no way to compute the unique public base class of a type if such one exists. Such a trait could be very useful if one needs to instantiate a specialization made for the root class whenever a derived class is passed as parameter. For example, imagine that you wanted to specialize std::hash
for a class hierarchy---instead of specializing each class, you could specialize the std::hash<root_class>
and provide a partial specialization that worked for all derived classes.
This ability---to specify operations in terms of their equivalent in the root class---can be done with e.g. normal functions, but there is, AFAIK, no way to do it for class templates. Being able to access compile-time information about the type-hierachy can be very powerful, and I therefore also suggest traits that computes the directly derived class whenever that is possible.
If the computation can not be done, the traits should fall back on an identity transformation. I expect this gives the best overall usability.
Proposed resolution:
Add the following to the synopsis in 21.3.3 [meta.type.synop] under "other transformations":
template< class T > struct direct_base_class; template< class T > struct direct_derived_class; template< class T > struct root_base_class;
Add three new entries to table 51 (21.3.9.7 [meta.trans.other]) with the following content
Template Condition Commentstemplate< class T > struct direct_base_class;
T
shall be a complete type. The member typedeftype
shall equal the accessible unambiguous direct base class ofT
. If no such type exists, the member typedeftype
shall equalT
.template< class T > struct direct_derived_class;
T
shall be a complete type. The member typedeftype
shall equal the unambiguous type which hasT
as an accessible unambiguous direct base class. If no such type exists, the member typedeftype
shall equalT
.template< class T > struct root_base_class;
T
shall be a complete type. The member typedeftype
shall equal the accessible unambiguous most indirect base class ofT
. If no such type exists, the member typedef type shall equalT
.
Rationale:
2008-9-16 San Francisco: Issue pulled by author prior to being reviewed by the LWG.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4