May 2017
Intermediate to advanced
590 pages
17h 18m
English
Use static_assert declarations to ensure that conditions in different scopes are met:
struct alignas(8) item { int id; bool active; double value; }; static_assert(sizeof(item) == 16, "size of item must be 16 bytes");
template <typename T> class pod_wrapper { static_assert(std::is_pod<T>::value, "POD type expected!"); T value; }; struct point { int x; int y; }; pod_wrapper<int> w1; // OK pod_wrapper<point> w2; // OK pod_wrapper<std::string> w3; // error: POD type expected
Read now
Unlock full access