20#ifndef GCC_MUX_UTILS_H
21#define GCC_MUX_UTILS_H 1
48template<
typename T1,
typename T2 = T1>
67 typename Enable =
typename
68 std::enable_if<std::is_convertible<T *, T1 *>::value
69 != std::is_convertible<T *, T2 *>::value>
::type>
153template<
typename T1,
typename T2>
158 return reinterpret_cast<char *
> (ptr);
161template<
typename T1,
typename T2>
166 return reinterpret_cast<char *
> (ptr) + 1;
169template<
typename T1,
typename T2>
170template<
typename T,
typename Enable>
172 : m_ptr (reinterpret_cast<char *> (ptr))
174 if (std::is_convertible<T *, T2 *>::value)
181template<
typename T1,
typename T2>
185 return is_first () ? known_first () :
nullptr;
188template<
typename T1,
typename T2>
197 return (uintptr_t (m_ptr) - 1) & 1 ? nullptr : known_second ();
200template<
typename T1,
typename T2>
205 static_assert (std::is_convertible<T1 *, T>::value
206 != std::is_convertible<T2 *, T>::value,
207 "Ambiguous pointer type");
208 if (std::is_convertible<T2 *, T>::value)
214template<
typename T1,
typename T2>
219 static_assert (std::is_convertible<T1 *, T>::value
220 != std::is_convertible<T2 *, T>::value,
221 "Ambiguous pointer type");
222 if (std::is_convertible<T2 *, T>::value)
225 return reinterpret_cast<T
> (m_ptr - 1);
230 return reinterpret_cast<T
> (m_ptr);
234template<
typename T1,
typename T2>
239 static_assert (std::is_convertible<T1 *, T>::value
240 != std::is_convertible<T2 *, T>::value,
241 "Ambiguous pointer type");
242 if (std::is_convertible<T2 *, T>::value)
245 return reinterpret_cast<T
> (m_ptr - 1);
250 return reinterpret_cast<T
> (m_ptr);
Definition mux-utils.h:50
T2 * second_or_null() const
Definition mux-utils.h:190
bool is_a() const
Definition mux-utils.h:203
static pointer_mux first(T1 *)
Definition mux-utils.h:155
T as_a() const
Definition mux-utils.h:217
T dyn_cast() const
Definition mux-utils.h:237
void set_second(T2 *ptr)
Definition mux-utils.h:77
bool operator!=(const pointer_mux &pm) const
Definition mux-utils.h:122
bool is_second() const
Definition mux-utils.h:83
T1 * first_or_null() const
Definition mux-utils.h:183
pointer_mux(T *ptr)
Definition mux-utils.h:171
static pointer_mux second(T2 *)
Definition mux-utils.h:163
T1 * known_first() const
Definition mux-utils.h:87
pointer_mux(std::nullptr_t)
Definition mux-utils.h:61
bool operator==(const pointer_mux &pm) const
Definition mux-utils.h:120
bool is_first() const
Definition mux-utils.h:80
pointer_mux(char *ptr)
Definition mux-utils.h:144
T2 * known_second() const
Definition mux-utils.h:91
char * m_ptr
Definition mux-utils.h:150
void set_first(T1 *ptr)
Definition mux-utils.h:76
static struct token T
Definition gengtype-parse.cc:45
Definition gengtype.h:252
#define bool
Definition system.h:886
#define gcc_checking_assert(EXPR)
Definition system.h:821