LOKI library reading static

zhaozj2021-02-16  44

Not only static_check in Loki static_check.h, there is a static_size_assert.

I have always ignored this static_size_assert, and now I suddenly discovered that it can be written almost anywhere in the code, and Static_Check can only be placed in the function. Imitation static_size_assert also implements static_check that can be placed in any place is not difficult.

Loki makes such a choice, I think it should be like this to bring extra MSG information. For small items, it can be more tempting to anywhere than with extra information.

Template struct compiletimeerror; template <> struct compiletimeerror {}; template struct static_assert_test {};

// # define STATIC_CHECK (expr) do {CompileTimeError <(expr)> STATIC_CHECK_ERROR; (void) STATIC_CHECK_ERROR;} while (0) #define STATIC_CHECK (expr) typedef static_assert_test )> static_check_typedef_

Because it is engaged in embedded system development, I always want to know the size of a structure at any time. If you want to run a schedule, it is too much trouble. So, think of using the stuff to print it out in the compile period. Unfortunately, this is achieved by generating compilation errors, I can't implement this function without affecting normal compilation.

#define static_size_trace (type) / template struct sizeof _ ## Type; / typef static_assert_test )> static_size_trace_typedef_

转载请注明原文地址:https://www.9cbs.com/read-26687.html

New Post(0)