36 #ifndef UTIL_ACCESS_CASTED_O_H 37 #define UTIL_ACCESS_CASTED_O_H 39 #include <type_traits> 46 using std::remove_pointer;
47 using std::remove_reference;
48 using std::is_convertible;
49 using std::is_polymorphic;
50 using std::is_base_of;
53 template <
typename SRC,
typename TAR>
56 template <
typename SRC,
typename TAR>
57 struct can_cast<SRC*,TAR*> {
enum { value = is_base_of<SRC,TAR>::value };};
59 template <
typename SRC,
typename TAR>
60 struct can_cast<SRC*&,TAR*> {
enum { value = is_base_of<SRC,TAR>::value };};
62 template <
typename SRC,
typename TAR>
63 struct can_cast<SRC&,TAR&> {
enum { value = is_base_of<SRC,TAR>::value };};
69 typedef typename remove_pointer<
70 typename remove_reference<T>::type>::type TPlain;
72 enum { value = is_polymorphic<TPlain>::value };
75 template <
typename SRC,
typename TAR>
78 enum { value =
can_cast<SRC,TAR>::value
84 template <
typename SRC,
typename TAR>
87 enum { value =
can_cast<SRC,TAR>::value
94 template <
typename SRC,
typename TAR>
97 enum { value = is_convertible<SRC,TAR>::value
109 static X create() {
return X(); }
114 static X*& create() {
static X* nullP(0);
return nullP; }
122 template<
typename RET>
127 static RET access (...) {
return ifEmpty(); }
128 static RET ifEmpty () {
return EmptyVal<RET>::create(); }
131 template<
typename TAR>
136 template<
typename ELM>
137 static typename std::enable_if< use_dynamic_downcast<ELM&,TAR>::value,
141 return dynamic_cast<TAR
> (elem);
144 template<
typename ELM>
145 static typename std::enable_if< use_static_downcast<ELM&,TAR>::value,
149 return static_cast<TAR
> (elem);
152 template<
typename ELM>
153 static typename std::enable_if< use_conversion<ELM&,TAR>::value,