I'd like to use static_assert
in my C++11 project to do some compile time check.
As my understanding, static_assert
won't be executed at runtime, right?
If so, when I compile my project by executing the command about compilation, such as gcc ...
, the compiler will build the static_assert
into the binary file or the static_assert
will be totally ignored, just like a comment?
Is static_assert compiled into the binary file
No.
As my understanding, static_assert won't be executed at runtime, right?
Right.
the compiler will build the static_assert into the binary file
No.
the static_assert will be totally ignored, just like a comment?
No, it's not a comment - the expression is checked, and if the expression is false, then a message is shown. When the expression is not a constant (can't be computed at compile time) then also a message is shown.