1 //===- Support/TypeInfo.h - Support class for type_info objects -*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This class makes std::type_info objects behave like first class objects that
11 // can be put in maps and hashtables. This code is based off of code in the
12 // Loki C++ library from the Modern C++ Design book.
14 //===----------------------------------------------------------------------===//
16 #ifndef SUPPORT_TYPEINFO_H
17 #define SUPPORT_TYPEINFO_H
24 TypeInfo() { // needed for containers
25 struct Nil {}; // Anonymous class distinct from all others...
29 TypeInfo(const std::type_info &ti) : Info(&ti) { // non-explicit
32 // Access for the wrapped std::type_info
33 const std::type_info &get() const {
37 // Compatibility functions
38 bool before(const TypeInfo &rhs) const {
39 return Info->before(*rhs.Info);
41 const char *getClassName() const {
46 const std::type_info *Info;
49 // Comparison operators
50 inline bool operator==(const TypeInfo &lhs, const TypeInfo &rhs) {
51 return lhs.get() == rhs.get();
54 inline bool operator<(const TypeInfo &lhs, const TypeInfo &rhs) {
55 return lhs.before(rhs);
58 inline bool operator!=(const TypeInfo &lhs, const TypeInfo &rhs) {
62 inline bool operator>(const TypeInfo &lhs, const TypeInfo &rhs) {
66 inline bool operator<=(const TypeInfo &lhs, const TypeInfo &rhs) {
70 inline bool operator>=(const TypeInfo &lhs, const TypeInfo &rhs) {
74 } // End llvm namespace