Created
January 9, 2022 03:21
-
-
Save dbremner/47ff95d7738c0cfe577eba796d2540e1 to your computer and use it in GitHub Desktop.
cast wrappers for clang nullability types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Cast a nullable pointer to a non-null pointer | |
/// This is unsafe and should be justified with a comment | |
/// containing the keyword WHY | |
/// For example, "WHY - checked" | |
template <typename T> | |
[[nodiscard]] constexpr static inline auto | |
as_live(T *_Nullable value) -> T *_Nonnull | |
{ | |
return static_cast<T *_Nonnull>(value); | |
} | |
/// Cast a const nullable pointer to a const non-null pointer | |
/// This is unsafe and should be justified with a comment | |
/// containing the keyword WHY | |
/// For example, "WHY - checked" | |
template <typename T> | |
[[nodiscard]] constexpr static inline auto | |
as_const_live(const T *_Nullable value) -> const T *_Nonnull | |
{ | |
return static_cast<const T *_Nonnull>(value); | |
} | |
/// Cast a pure nullable pointer to a pure non-null pointer | |
/// This is unsafe and should be justified with a comment | |
/// containing the keyword WHY | |
/// For example, "WHY - checked" | |
template <typename T> | |
[[nodiscard]] constexpr static inline auto | |
as_pure_live(const T *const _Nullable value) -> const T *const _Nonnull | |
{ | |
return static_cast<const T *const _Nonnull>(value); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment