In the options class, I'm working on raw storage - a char array:
alignas() char storage[];
An assignment operator is something like:
template<class X> void operator=(const X &x) {
while the code to get the stored object:
template<class X> const X &get() {
It seems to work, but is it always clearly defined? I worry about safely dereferencing a pointer (is this permissible by rules such as anti-aliasing?).
Are there any differences between the current implementation and
return *static_cast<const X *>(static_cast<const void *>(storage));
Related Question / Answer:
https://stackoverflow.com/questions/8468/ ... (see James Kanze's comments ).
EDIT
The second question already has an answer here: C ++. When do we prefer to use the dug-up static_cast by reinterpret_cast
c ++ c ++ 11 static-cast reinterpret-cast variant
manlio
source share