Skip to content

Commit

Permalink
Add LIBHAT_ASSUME macro
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeroMemes committed Aug 1, 2024
1 parent d8404cb commit 1133b07
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions include/libhat/Defines.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,18 @@
}
#define LIBHAT_UNREACHABLE() hat::detail::unreachable_impl()
#endif

#if __has_cpp_attribute(assume)
#define LIBHAT_ASSUME(...) [[assume(__VA_ARGS__)]]
#elif defined(_MSC_VER)
#define LIBHAT_ASSUME(...) __assume(__VA_ARGS__)
#elif defined(__clang__)
#define LIBHAT_ASSUME(...) __builtin_assume(__VA_ARGS__)
#else
#define LIBHAT_ASSUME(...) \
do { \
if (!(__VA_ARGS__)) { \
LIBHAT_UNREACHABLE(); \
} \
} while (0)
#endif

0 comments on commit 1133b07

Please sign in to comment.