diff options
Diffstat (limited to 'lib/mesa/src/util/u_vector.h')
-rw-r--r-- | lib/mesa/src/util/u_vector.h | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/lib/mesa/src/util/u_vector.h b/lib/mesa/src/util/u_vector.h index 1283e78b7..5a1a08934 100644 --- a/lib/mesa/src/util/u_vector.h +++ b/lib/mesa/src/util/u_vector.h @@ -21,7 +21,7 @@ * IN THE SOFTWARE. */ -/* +/* * u_vector is a vector based queue for storing arbitrary * sized arrays of objects without using a linked list. */ @@ -98,10 +98,18 @@ u_vector_finish(struct u_vector *queue) free(queue->data); } +#ifdef __cplusplus +#define u_vector_element_cast(elem) (decltype(elem)) +#else +#define u_vector_element_cast(elem) (void *) +#endif + #define u_vector_foreach(elem, queue) \ STATIC_ASSERT(__builtin_types_compatible_p(__typeof__(queue), struct u_vector *)); \ for (uint32_t __u_vector_offset = (queue)->tail; \ - elem = (void *)((char *)(queue)->data + (__u_vector_offset & ((queue)->size - 1))), __u_vector_offset != (queue)->head; \ + elem = u_vector_element_cast(elem)((char *)(queue)->data + \ + (__u_vector_offset & ((queue)->size - 1))), \ + __u_vector_offset != (queue)->head; \ __u_vector_offset += (queue)->element_size) #ifdef __cplusplus |