Quantcast
Channel: Test for "POD-ness" in c++/c++11? - Stack Overflow
Viewing all articles
Browse latest Browse all 4

Test for "POD-ness" in c++/c++11?

$
0
0

I have some code which takes a packed POD structure/class and copies it into a memory block.

struct A{   int a;   int b;} a;memcpy(mymemoryblock, (void *)&a, sizeof(A));// later I get a reply and...memcpy((void *)&a, mymemoryblock, sizeof(A));

This is only valid for POD types of data, and what I would like to know if there is a way I can test for POD-ness. If someone accidentally adds a member function to this class, the memcpy operations become invalid, but still compilable. This leads to very difficult to detect bugs.

Is there a is_POD_type(A) function, or some other trick that can be used to detect PODness at runtime or compile time?


Viewing all articles
Browse latest Browse all 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>