libcopp 2.3.1
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
nullability.h
Go to the documentation of this file.
1// Copyright 2025 owent
2// Created by owent on 2025-03-03
3
4#pragma once
5
6#include <memory>
7#include <type_traits>
8
10#include "libcopp/utils/config/libcopp_build_features.h"
12
13LIBCOPP_COPP_NAMESPACE_BEGIN
14namespace nostd {
15template <class, class = void>
16struct __is_nullability_compatible : ::std::false_type {};
17
18// Allow custom to support nullability by define nullability_compatible_type as void
19template <class T>
20struct __is_nullability_compatible<T, void_t<typename T::nullability_compatible_type>> : ::std::true_type {};
21
22template <class T>
26
27template <class T>
29 LIBCOPP_UTIL_MACRO_INLINE_VARIABLE static constexpr const bool value = true;
30};
31
32template <class T, class U>
34 LIBCOPP_UTIL_MACRO_INLINE_VARIABLE static constexpr const bool value = true;
35};
36
37template <class T, class... Deleter>
38struct __is_nullability_support<std::unique_ptr<T, Deleter...>> {
39 LIBCOPP_UTIL_MACRO_INLINE_VARIABLE static constexpr const bool value = true;
40};
41
42template <class T>
43struct __is_nullability_support<std::shared_ptr<T>> {
44 LIBCOPP_UTIL_MACRO_INLINE_VARIABLE static constexpr const bool value = true;
45};
46
47template <class T>
49 static_assert(__is_nullability_support<remove_cv_t<T>>::value,
50 "Template argument must be a raw or supported smart pointer "
51 "type. See nostd/nullability.h.");
52 using type = T;
53};
54
55template <class T>
57 static_assert(__is_nullability_support<remove_cv_t<T>>::value,
58 "Template argument must be a raw or supported smart pointer "
59 "type. See nostd/nullability.h.");
60 using type = T;
61};
62
63template <class T>
65 static_assert(__is_nullability_support<remove_cv_t<T>>::value,
66 "Template argument must be a raw or supported smart pointer "
67 "type. See nostd/nullability.h.");
68 using type = T;
69};
70
71template <class T, class = typename __enable_nullable<T>::type>
73#if LIBCOPP_UTIL_HAVE_CPP_ATTRIBUTE(clang::annotate)
74 [[clang::annotate("Nullable")]]
75#endif
76 = T;
77
78template <class T, class = typename __enable_nonnull<T>::type>
80#if LIBCOPP_UTIL_HAVE_CPP_ATTRIBUTE(clang::annotate)
81 [[clang::annotate("Nonnull")]]
82#endif
83 = T;
84
85template <class T, class = typename __enable_nullability_unknown<T>::type>
87#if LIBCOPP_UTIL_HAVE_CPP_ATTRIBUTE(clang::annotate)
88 [[clang::annotate("Nullability_Unspecified")]]
89#endif
90 = T;
91
92} // namespace nostd
93LIBCOPP_COPP_NAMESPACE_END
#define LIBCOPP_UTIL_MACRO_INLINE_VARIABLE
T nullability_unknown
Definition nullability.h:90
T nullable
Definition nullability.h:76
T nonnull
Definition nullability.h:83
STL namespace.
static LIBCOPP_UTIL_MACRO_INLINE_VARIABLE constexpr const bool value
Definition nullability.h:24