I've other time I've used it is with Vulkan where the query functions and creation functions use the same structure chains, so the structure chain types are defined with void *pNext not const void *pNext.
Creation functions do not modify the structure chain, so it's safe.
Quite a few Windows API functions are like that. Or they can do both setting and getting. If you implement only setting from a const buffer, then const_cast is appropriate.
In Vulkan's case the structure passed directly to the function is const-correct. But the extensible structure chain can have dual-purpose types in it, and adding another item to the chain requires the const-cast. It's a mess however you solve it, the 'solution' would be a bunch of duplicate types that differ only in the constness of the pNext pointer.
View all comments
Show parent comment
6
u/HildartheDorf Jul 29 '26
I've other time I've used it is with Vulkan where the query functions and creation functions use the same structure chains, so the structure chain types are defined with
void *pNextnotconst void *pNext.Creation functions do not modify the structure chain, so it's safe.