1 //===- Support/TypeInfo.h - Support class for type_info objects --*- C++ -*--=//
3 // This class makes std::type_info objects behave like first class objects that
4 // can be put in maps and hashtables. This code is based off of code in the
5 // Loki C++ library from the Modern C++ Design book.
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_SUPPORT_TYPEINFO_H
10 #define LLVM_SUPPORT_TYPEINFO_H
15 TypeInfo() { // needed for containers
16 struct Nil {}; // Anonymous class distinct from all others...
20 TypeInfo(const std::type_info &ti) : Info(&ti) { // non-explicit
23 // Access for the wrapped std::type_info
24 const std::type_info &get() const {
28 // Compatibility functions
29 bool before(const TypeInfo &rhs) const {
30 return Info->before(*rhs.Info);
32 const char *getClassName() const {
37 const std::type_info *Info;
40 // Comparison operators
41 inline bool operator==(const TypeInfo &lhs, const TypeInfo &rhs) {
42 return lhs.get() == rhs.get();
45 inline bool operator<(const TypeInfo &lhs, const TypeInfo &rhs) {
46 return lhs.before(rhs);
49 inline bool operator!=(const TypeInfo &lhs, const TypeInfo &rhs) {
53 inline bool operator>(const TypeInfo &lhs, const TypeInfo &rhs) {
57 inline bool operator<=(const TypeInfo &lhs, const TypeInfo &rhs) {
61 inline bool operator>=(const TypeInfo &lhs, const TypeInfo &rhs) {