4 ms·
I don't think that node is a POD type because it holds two reference members. More on this here: http://stackoverflow.com/questions/4178175/what-are-aggregates-
by zvrba 12y ago
I don't think that node is a POD type because it holds two reference members. More on this here: http://stackoverflow.com/questions/4178175/what-are-aggregates-and-pods-and-how-why-are-they-special/7189821#7189821 http://stackoverflow.com/questions/4178175/what-are-aggregat...
In particular, node does not have a trivial copy-assignment operator. Further below it seems that classes/structs containing references do not have a standard layout. Hence, it is not a POD.
Also, the standard does not guarantee anything about your usage of reinterpret_cast.
Maybe the code you provided works on your particular implementation, but I'm willing to bet that it violates the standard in several ways.
EDIT: cool trick though. I forgot that a name is in scope and refers to itself just after it is declared, i.e., that you can refer to nil while constructing nil.
- evincarofautumn 12y agoAh, you’re right, it’s not POD, but it should still be safe to reuse the storage in this way. You’re also right about the reinterpret_cast, but it’s not necessary for this example because placement new takes a “void” pointer—I just did it to get the convenience of “+ 1” instead of “+ sizeof(node)”.