17 Language support library [support] (original) (raw)
17.7 Type identification [support.rtti]
The header <typeinfo> defines a type associated with type information generated by the implementation.
It also defines two types for reporting dynamic type identification errors.
17.7.1 Header synopsis [typeinfo.syn]
namespace std { class type_info; class bad_cast; class bad_typeid; }
17.7.2 Class type_info [type.info]
namespace std { class type_info { public: virtual ~type_info(); bool operator==(const type_info& rhs) const noexcept; bool before(const type_info& rhs) const noexcept; size_t hash_code() const noexcept; const char* name() const noexcept;
type_info(const type_info&) = delete;
type_info& operator=(const type_info&) = delete; }; }
The classtype_infodescribes type information generated by the implementation ([expr.typeid]).
Objects of this class effectively store a pointer to a name for the type, and an encoded value suitable for comparing two types for equality or collating order.
The names, encoding rule, and collating sequence for types are all unspecifiedand may differ between programs.
bool operator==(const type_info& rhs) const noexcept;
Effects:Compares the current object with rhs.
Returns: trueif the two values describe the same type.
bool before(const type_info& rhs) const noexcept;
Effects:Compares the current object with rhs.
Returns: trueif*thisprecedes rhs in the implementation's collation order.
size_t hash_code() const noexcept;
Returns:An unspecified value, except that within a single execution of the program, it shall return the same value for any two type_infoobjects which compare equal.
Remarks:An implementation should return different values for twotype_info objects which do not compare equal.
const char* name() const noexcept;
Returns:An implementation-defined ntbs.
17.7.3 Class bad_cast [bad.cast]
namespace std { class bad_cast : public exception { public:
const char* what() const noexcept override;}; }
The classbad_castdefines the type of objects thrown as exceptions by the implementation to report the execution of an invaliddynamic_castexpression ([expr.dynamic.cast]).
const char* what() const noexcept override;
Returns:An implementation-defined ntbs.
17.7.4 Class bad_typeid [bad.typeid]
namespace std { class bad_typeid : public exception { public:
const char* what() const noexcept override;}; }
The classbad_typeiddefines the type of objects thrown as exceptions by the implementation to report a null pointer in atypeidexpression ([expr.typeid]).
const char* what() const noexcept override;
Returns:An implementation-defined ntbs.