Mirror reflection library 0.5.13
|
00001 00010 #ifndef MIRROR_RAW_PTR_AUDITOR_1011291729_HPP 00011 #define MIRROR_RAW_PTR_AUDITOR_1011291729_HPP 00012 00013 #include <type_traits> 00014 00015 MIRROR_NAMESPACE_BEGIN 00016 namespace aux { 00017 00018 #ifdef MIRROR_FAST_RAW_PTR 00019 template <typename TypeCmp> 00020 class ptr_cast_auditor 00021 { 00022 public: 00023 ptr_cast_auditor(void) = default; 00024 00025 template <typename T> 00026 inline ptr_cast_auditor(T*) 00027 { } 00028 00029 template <typename T> 00030 inline ptr_cast_auditor& operator = (T*) 00031 { 00032 return *this; 00033 } 00034 00035 inline bool convertible_to(const ptr_cast_auditor&) const 00036 { 00037 return true; 00038 } 00039 }; 00040 #else // ! MIRROR_FAST_RAW_PTR 00041 template <typename TypeCmp> 00042 class ptr_cast_auditor 00043 { 00044 private: 00045 // the object used for comparing types 00046 typename TypeCmp::type cmpr; 00047 // whether the type is const 00048 bool const_; 00049 // whether the type is volatile 00050 bool volatile_; 00051 public: 00052 // default construction 00053 ptr_cast_auditor(void) 00054 : cmpr(TypeCmp::template create<void>()) 00055 , const_(false) 00056 , volatile_(false) 00057 { } 00058 00059 // initialization from a typed pointer 00060 template <typename T> 00061 ptr_cast_auditor(T*) 00062 : cmpr(TypeCmp::template create<typename std::remove_cv<T>::type>()) 00063 , const_(std::is_const<T>::value) 00064 , volatile_(std::is_volatile<T>::value) 00065 { } 00066 00068 template <typename T> 00069 ptr_cast_auditor& operator = (T*) 00070 { 00071 cmpr = TypeCmp::template create< 00072 typename std::remove_cv<T>::type 00073 >(); 00074 const_ = std::is_const<T>::value; 00075 volatile_ = std::is_volatile<T>::value; 00076 return *this; 00077 } 00078 00082 bool convertible_to(const ptr_cast_auditor& x) const 00083 { 00084 return (this->cmpr == x.cmpr) && 00085 (!this->const_ || x.const_) && 00086 (!this->volatile_ || x.volatile_); 00087 } 00088 }; 00089 #endif 00090 00091 } // namespace aux 00092 MIRROR_NAMESPACE_END 00093 00094 #endif // MIRROR_RAW_PTR_TYPE_INFO_CMP_HPP