, , usabe :
#include <iostream>
#include <algorithm>
#pragma pack(push)
#pragma pack(1)
struct Errors
{
bool error1;
bool error2;
bool error3;
inline const bool* begin() const
{
return reinterpret_cast<const bool*>(this);
}
inline const bool* end() const
{
return reinterpret_cast<const bool*>(this + 1);
}
inline bool any() const
{
return std::count(begin(), end(), true) > 0;
}
inline bool all() const
{
return std::count(begin(), end(), true) == end() - begin();
}
inline bool none() const
{
return std::count(begin(), end(), true) == 0;
}
};
#pragma pack(pop)
int main()
{
Errors e;
memset(&e, 0, sizeof(e));
e.error1 = false;
e.error2 = false;
e.error3 = false;
std::cout << "any=" << e.any() << ", all=" << e.all() << ", none=" << e.none() << std::endl;
e.error1 = true;
e.error2 = false;
e.error3 = false;
std::cout << "any=" << e.any() << ", all=" << e.all() << ", none=" << e.none() << std::endl;
e.error1 = true;
e.error2 = true;
e.error3 = true;
std::cout << "any=" << e.any() << ", all=" << e.all() << ", none=" << e.none() << std::endl;
return 0;
}
, .
-
enum class Enum
{
Error1,
Error2,
Error3
};
typedef std::set<Error> Errors;