Section: 17.7.7 [type.index] Status: NAD Concepts Submitter: Doug Gregor Opened: 2009-03-20 Last modified: 2016-01-28
Priority: Not Prioritized
View all other issues in [type.index].
View all issues with NAD Concepts status.
Discussion:
Addresses DE 17
DE-17:
The class type_index should be removed; it provides no additional
functionality beyond providing appropriate concept maps.
[ 2009-03-31 Peter adds: ]
It is not true, in principle, that
std::type_indexprovides no utility compared to barestd::type_info*.
std::type_indexcan avoid the lifetime issues withtype_infowhen the DLL that has produced thetype_infoobject is unloaded. A rawtype_info*does not, and cannot, provide any protection in this case. Atype_indexcan (if the implementor so chooses) because it can wrap a smart (counted or even cloning) pointer to thetype_infodata that is needed forname()andbefore()to work.
Proposed resolution:
Modify the header <typeinfo> synopsis in 17.7 [support.rtti]p1 as follows:
namespace std {
class type_info;
class type_index;
template <class T> struct hash;
template<> struct hash<type_indexconst type_info *> : public std::unary_function<type_indexconst type_info *, size_t> {
size_t operator()(type_indexconst type_info * indext) const;
};
concept_map LessThanComparable<const type_info *> see below
class bad_cast;
class bad_typeid;
}
Add the following new subsection
18.7.1.1 Template specialization
hash<const type_info *>[type.info.hash]size_t operator()(const type_info *x) const;
- Returns:
x->hash_code()
Add the following new subsection
18.7.1.2
type_infoconcept map [type.info.concepts]concept_map LessThanComparable<const type_info *> { bool operator<(const type_info *x, const type_info *y) { return x->before(*y); } bool operator<=(const type_info *x, const type_info *y) { return !y->before(*x); } bool operator>(const type_info *x, const type_info *y) { return y->before(*x); } bool operator>=(const type_info *x, const type_info *y) { return !x->before(*y); } }
- Note: provides a well-defined ordering among
type_info constpointers, which makes such pointers usable in associative containers (23.4).
Remove section 17.7.7 [type.index]