1 ////////////////////////////////////////////////////////////////////////////////
3 // Copyright (c) 2001 by Andrei Alexandrescu
4 // This code accompanies the book:
5 // Alexandrescu, Andrei. "Modern C++ Design: Generic Programming and Design
6 // Patterns Applied". Copyright (c) 2001. Addison-Wesley.
7 // Permission to use, copy, modify, distribute and sell this software for any
8 // purpose is hereby granted without fee, provided that the above copyright
9 // notice appear in all copies and that both that copyright notice and this
10 // permission notice appear in supporting documentation.
11 // The author or Addison-Wesley Longman make no representations about the
12 // suitability of this software for any purpose. It is provided "as is"
13 // without express or implied warranty.
14 ////////////////////////////////////////////////////////////////////////////////
15 #ifndef LOKI_LOKITYPEINFO_INC_
16 #define LOKI_LOKITYPEINFO_INC_
18 // $Id: LokiTypeInfo.h 748 2006-10-17 19:49:08Z syntheticpp $
27 ////////////////////////////////////////////////////////////////////////////////
29 // Purpose: offer a first-class, comparable wrapper over std::type_info
30 ////////////////////////////////////////////////////////////////////////////////
36 TypeInfo(); // needed for containers
37 TypeInfo(const std::type_info &); // non-explicit
39 // Access for the wrapped std::type_info
40 const std::type_info &Get() const;
41 // Compatibility functions
42 bool before(const TypeInfo &rhs) const;
43 const char *name() const;
46 const std::type_info *pInfo_;
51 inline TypeInfo::TypeInfo()
54 pInfo_ = &typeid(Nil);
58 inline TypeInfo::TypeInfo(const std::type_info &ti)
64 inline bool TypeInfo::before(const TypeInfo &rhs) const
67 // type_info::before return type is int in some VC libraries
68 return pInfo_->before(*rhs.pInfo_) != 0;
71 inline const std::type_info &TypeInfo::Get() const
77 inline const char *TypeInfo::name() const
80 return pInfo_->name();
83 // Comparison operators
85 inline bool operator==(const TypeInfo &lhs, const TypeInfo &rhs)
86 // type_info::operator== return type is int in some VC libraries
88 return (lhs.Get() == rhs.Get()) != 0;
91 inline bool operator<(const TypeInfo &lhs, const TypeInfo &rhs)
93 return lhs.before(rhs);
96 inline bool operator!=(const TypeInfo &lhs, const TypeInfo &rhs)
101 inline bool operator>(const TypeInfo &lhs, const TypeInfo &rhs)
106 inline bool operator<=(const TypeInfo &lhs, const TypeInfo &rhs)
111 inline bool operator>=(const TypeInfo &lhs, const TypeInfo &rhs)
117 #endif // end file guardian