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
22 TypeInfo() { // needed for containers
23 struct Nil {}; // Anonymous class distinct from all others...
27 TypeInfo(const std::type_info &ti) : Info(&ti) { // non-explicit
30 // Access for the wrapped std::type_info
31 const std::type_info &get() const {
35 // Compatibility functions
36 bool before(const TypeInfo &rhs) const {
37 return Info->before(*rhs.Info);
39 const char *getClassName() const {
44 const std::type_info *Info;
47 // Comparison operators
48 inline bool operator==(const TypeInfo &lhs, const TypeInfo &rhs) {
49 return lhs.get() == rhs.get();
52 inline bool operator<(const TypeInfo &lhs, const TypeInfo &rhs) {
53 return lhs.before(rhs);
56 inline bool operator!=(const TypeInfo &lhs, const TypeInfo &rhs) {
60 inline bool operator>(const TypeInfo &lhs, const TypeInfo &rhs) {
64 inline bool operator<=(const TypeInfo &lhs, const TypeInfo &rhs) {
68 inline bool operator>=(const TypeInfo &lhs, const TypeInfo &rhs) {