lean cpp library
A lean C++ library providing efficient utility classes for high-performance C++ applications.
|
00001 /*****************************************************/ 00002 /* lean Meta (c) Tobias Zirr 2011 */ 00003 /*****************************************************/ 00004 00005 #ifndef LEAN_META_CONDITIONAL 00006 #define LEAN_META_CONDITIONAL 00007 00008 namespace lean 00009 { 00010 namespace meta 00011 { 00012 00014 template <bool Condition, class TrueType, class FalseType> 00015 struct conditional_type 00016 { 00018 typedef FalseType type; 00019 }; 00020 00021 #ifndef DOXYGEN_SKIP_THIS 00022 00023 template <class TrueType, class FalseType> 00024 struct conditional_type<true, TrueType, FalseType> 00025 { 00026 typedef TrueType type; 00027 }; 00028 00029 #endif 00030 00032 template <class Type1, class Type2> 00033 struct first_non_void 00034 { 00036 typedef Type1 type; 00037 }; 00038 00039 #ifndef DOXYGEN_SKIP_THIS 00040 00041 template <class Type2> 00042 struct first_non_void<void, Type2> 00043 { 00044 typedef Type2 type; 00045 }; 00046 00047 template <> 00048 struct first_non_void<void, void> 00049 { 00050 }; 00051 00052 #endif 00053 00055 template <class FullType, class BaseType> 00056 struct complete_type_or_base 00057 { 00058 private: 00059 typedef char complete[1]; 00060 typedef char incomplete[2]; 00061 00062 static complete& check_type(const BaseType*); 00063 static incomplete& check_type(const void*); 00064 00065 public: 00067 static const bool is_complete = ( 00068 sizeof( check_type( static_cast<FullType*>(nullptr) ) ) 00069 == 00070 sizeof(complete) ); 00071 00073 typedef typename conditional_type<is_complete, FullType, BaseType>::type type; 00074 }; 00075 00076 } // namespace 00077 00078 using meta::conditional_type; 00079 using meta::first_non_void; 00080 using meta::complete_type_or_base; 00081 00082 } // namespace 00083 00084 #endif