Reference: https://en.cppreference.com/w/cpp/language/eval_order
C++ 17 has settled the long time evaluation order issues in C/C++,
the modified list:
- For
e1[ e2 ] e1.e2 e1.*e2 e1->*e2 e1 << e2 e1 >> e2
e1 is guaranteed to be evaluated before e2 now, so that the evaluation order is left to right. However, note that the evaluation order of different arguments of the same function call is still undefined.
That is, ine1.f(a1,a2,a3)
e1.f is guaranteed to be evaluated before a1, a2, and a3 now.
However, the evaluation order of a1, a2, and a3 is still undefined. - In all assignment operators
e2 = e1 e2 += e1 e2 *= e1
the right-hand side e1 is guaranteed to be evaluated before the left-hand side e2 now. - Finally, in new expressions like
new Type(e)
the allocation is now guaranteed to be performed before the evaluation e, and the initialization of the new value is guaranteed to happen before any usage of the allocated and initialized value. - Preprocessor Condition __has_include
e.g#if __has_include(<filesystem>) # include <filesystem> # define HAS_FILESYSTEM 1 #elif __has_include(<experimental/filesystem>) # include <experimental/filesystem> # define HAS_FILESYSTEM 1 # define FILESYSTEM_IS_EXPERIMENTAL 1 #elif __has_include("filesystem.hpp") # include "filesystem.hpp" # define HAS_FILESYSTEM 1 # define FILESYSTEM_IS_EXPERIMENTAL 1 #else # define HAS_FILESYSTEM 0 #endif
This could be handy and to replace cmake's library header existance check.
However, be aware that the conditions inside __has_include(...) evaluate to 1 (true) if a corresponding #include command would be valid.
Nothing else matters (e.g., the answer does not depend on whether the file was already included). Furthermore, the fact that the file exists does not prove that it has the expected contents.
It might be empty or invalid.
__has_include is a pure preprocessor feature. Using __has_include as condition in source code is not possible:if (__has_include(<filesystem>) { // ERROR }
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.