TypeInfo Class Reference

#include <Pt/TypeInfo.h>

Extended API for std::type_info. More...

Public Member Functions

 TypeInfo ()
 Construct a void type info.
 
 TypeInfo (const std::type_info &ti)
 Construct from type info.
 
bool before (const TypeInfo &rhs) const
 Determines order of TypeInfo instances.
 
const std::type_info & get () const
 Returns the type info.
 

Related Functions

bool operator!= (const TypeInfo &lhs, const TypeInfo &rhs)
 Inequal comparison.
 
bool operator< (const TypeInfo &lhs, const TypeInfo &rhs)
 Less-than comparison.
 
bool operator<= (const TypeInfo &lhs, const TypeInfo &rhs)
 Less-than or equal comparison.
 
bool operator== (const TypeInfo &lhs, const TypeInfo &rhs)
 Equal comparison.
 
bool operator> (const TypeInfo &lhs, const TypeInfo &rhs)
 Greater-than comparison.
 
bool operator>= (const TypeInfo &lhs, const TypeInfo &rhs)
 Greater-than or equal comparison.
 

Detailed Description

The normal std::type_info class is not copyable, so only raw pointers can be stored in containers such as std::vector. The TypeInfo class addresses this problem, by wrapping std::type_info into a type with value semantics. It also adds comparison operators, like less-than comparison, which allow to use it as the key for assoziative containers:

// OK, TypeInfo is copyable
std::vector<Pt::TypeInfo> typeVector;
// OK, TypeInfo is less-than comparable
std::map<Pt::TypeInfo, std::string> typeMap;