45 #ifndef UTIL_ACCESS_CASTED_O_H 46 #define UTIL_ACCESS_CASTED_O_H 48 #include <type_traits> 55 using std::remove_pointer;
56 using std::remove_reference;
57 using std::is_convertible;
58 using std::is_polymorphic;
59 using std::is_base_of;
62 template <
typename SRC,
typename TAR>
65 template <
typename SRC,
typename TAR>
66 struct can_cast<SRC*,TAR*> {
enum { value = is_base_of<SRC,TAR>::value };};
68 template <
typename SRC,
typename TAR>
69 struct can_cast<SRC*&,TAR*> {
enum { value = is_base_of<SRC,TAR>::value };};
71 template <
typename SRC,
typename TAR>
72 struct can_cast<SRC&,TAR&> {
enum { value = is_base_of<SRC,TAR>::value };};
78 typedef typename remove_pointer<
79 typename remove_reference<T>::type>::type TPlain;
81 enum { value = is_polymorphic<TPlain>::value };
84 template <
typename SRC,
typename TAR>
87 enum { value =
can_cast<SRC,TAR>::value
93 template <
typename SRC,
typename TAR>
96 enum { value =
can_cast<SRC,TAR>::value
103 template <
typename SRC,
typename TAR>
106 enum { value = is_convertible<SRC,TAR>::value
118 static X create() {
return X(); }
123 static X*& create() {
static X* nullP(0);
return nullP; }
131 template<
typename RET>
136 static RET access (...) {
return ifEmpty(); }
137 static RET ifEmpty () {
return EmptyVal<RET>::create(); }
140 template<
typename TAR>
145 template<
typename ELM>
146 static typename std::enable_if< use_dynamic_downcast<ELM&,TAR>::value,
150 return dynamic_cast<TAR
> (elem);
153 template<
typename ELM>
154 static typename std::enable_if< use_static_downcast<ELM&,TAR>::value,
158 return static_cast<TAR
> (elem);
161 template<
typename ELM>
162 static typename std::enable_if< use_conversion<ELM&,TAR>::value,