I have a struct of bools.
It contains no other data member but bool
.
struct foo {
bool b1 = false;
bool b2 = false;
bool b3 = false;
// many more ...
};
Without using reflection or code generation,
I'm looking for an easy way to set them all to true, and then set them all to false.
Is it legal everywhere to memset them?
foo f;
memset(&f, true, sizeof f);
memset(&f, false, sizeof f);
As long as I guarantee the data members are always primitives, is this a safe and well-defined operation? If not, are there any other suggestions for ensuring that a large set booleans (more of which may be added in the future), can be consistently all be set to true/false. I would also like to keep them false by default. The reason I want to set them all to true occasionally, is that its useful for unit tests and code coverage.