Type "Not a pointer POD" in C ++

Is there a term for a class / structure that is trivial and standard layout, but also does not contain pointer elements?

Basically I would like to refer to the "really" simple old data types. The data that I can extract from memory and save to disk, and read them back into memory for further processing, because it is nothing more than a set of int, characters, enumerations, etc.

Is there a way to test at compile time if the type is a β€œreally” plain-old data type?

connected:
What are POD types in C ++? What are aggregates and PODs and how / why are they special?

+7
c ++ types
source share
1 answer

This may depend on the semantics of the structure. I could imagine that a structure having int fields is the key to some temporary storage of temporary data (or cache memory). You still do not have to serialize those, but you need internal knowledge about this structure so that you can say 1 .

In general, in C ++ there are no functions for general serialization. Creating this automatic just a pointer - just the tip of the iceberg (if possible, quite accurate in general) - this is also impossible in a general way. C ++ still has no reflection and thus cannot check "every element" for some condition.

Realistic approaches can be:

  • preprocessing class sources before assembly to scan pointers
  • declaring all structures that need to be serialized using some macros that track types
  • regular template checking can be implemented for a set of known names for fields
However, they all have their limitations and, along with my earlier reservations, I'm not sure how practical they are.

1 This, of course, goes both ways; pointers can be used to store relative offsets and are therefore ideally serializable.

+1
source share

All Articles