NVIDIA DeepStream SDK API Reference

9.2 Release
includes/opentelemetry/nostd/internal/absl/base/macros.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.
3  * SPDX-License-Identifier: Apache-2.0
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 #ifndef OTABSL_BASE_MACROS_H_
19 #define OTABSL_BASE_MACROS_H_
20 
21 #include <cassert>
22 #include <cstddef>
23 
24 #include "attributes.h"
25 #include "optimization.h"
26 #include "port.h"
27 
28 // OTABSL_ARRAYSIZE()
29 //
30 // Returns the number of elements in an array as a compile-time constant, which
31 // can be used in defining new arrays. If you use this macro on a pointer by
32 // mistake, you will get a compile-time error.
33 #define OTABSL_ARRAYSIZE(array) \
34  (sizeof(::absl::OTABSL_OPTION_NAMESPACE_NAME::macros_internal::ArraySizeHelper(array)))
35 
36 namespace absl {
38 namespace macros_internal {
39 // Note: this internal template function declaration is used by OTABSL_ARRAYSIZE.
40 // The function doesn't need a definition, as we only use its type.
41 template <typename T, size_t N>
42 auto ArraySizeHelper(const T (&array)[N]) -> char (&)[N];
43 } // namespace macros_internal
45 } // namespace absl
46 
47 // kLinkerInitialized
48 //
49 // An enum used only as a constructor argument to indicate that a variable has
50 // static storage duration, and that the constructor should do nothing to its
51 // state. Use of this macro indicates to the reader that it is legal to
52 // declare a static instance of the class, provided the constructor is given
53 // the absl::OTABSL_OPTION_NAMESPACE_NAME::base_internal::kLinkerInitialized argument.
54 //
55 // Normally, it is unsafe to declare a static variable that has a constructor or
56 // a destructor because invocation order is undefined. However, if the type can
57 // be zero-initialized (which the loader does for static variables) into a valid
58 // state and the type's destructor does not affect storage, then a constructor
59 // for static initialization can be declared.
60 //
61 // Example:
62 // // Declaration
63 // explicit MyClass(absl::OTABSL_OPTION_NAMESPACE_NAME::base_internal:LinkerInitialized x) {}
64 //
65 // // Invocation
66 // static MyClass my_global(absl::OTABSL_OPTION_NAMESPACE_NAME::base_internal::kLinkerInitialized);
67 namespace absl {
69 namespace base_internal {
72 };
73 } // namespace base_internal
75 } // namespace absl
76 
77 // OTABSL_FALLTHROUGH_INTENDED
78 //
79 // Annotates implicit fall-through between switch labels, allowing a case to
80 // indicate intentional fallthrough and turn off warnings about any lack of a
81 // `break` statement. The OTABSL_FALLTHROUGH_INTENDED macro should be followed by
82 // a semicolon and can be used in most places where `break` can, provided that
83 // no statements exist between it and the next switch label.
84 //
85 // Example:
86 //
87 // switch (x) {
88 // case 40:
89 // case 41:
90 // if (truth_is_out_there) {
91 // ++x;
92 // OTABSL_FALLTHROUGH_INTENDED; // Use instead of/along with annotations
93 // // in comments
94 // } else {
95 // return x;
96 // }
97 // case 42:
98 // ...
99 //
100 // Notes: when compiled with clang in C++11 mode, the OTABSL_FALLTHROUGH_INTENDED
101 // macro is expanded to the [[clang::fallthrough]] attribute, which is analysed
102 // when performing switch labels fall-through diagnostic
103 // (`-Wimplicit-fallthrough`). See clang documentation on language extensions
104 // for details:
105 // https://clang.llvm.org/docs/AttributeReference.html#fallthrough-clang-fallthrough
106 //
107 // When used with unsupported compilers, the OTABSL_FALLTHROUGH_INTENDED macro
108 // has no effect on diagnostics. In any case this macro has no effect on runtime
109 // behavior and performance of code.
110 #ifdef OTABSL_FALLTHROUGH_INTENDED
111 #error "OTABSL_FALLTHROUGH_INTENDED should not be defined."
112 #endif
113 
114 // TODO(zhangxy): Use c++17 standard [[fallthrough]] macro, when supported.
115 #if defined(__clang__) && defined(__has_warning)
116 #if __has_feature(cxx_attributes) && __has_warning("-Wimplicit-fallthrough")
117 #define OTABSL_FALLTHROUGH_INTENDED [[clang::fallthrough]]
118 #endif
119 #elif defined(__GNUC__) && __GNUC__ >= 7
120 #define OTABSL_FALLTHROUGH_INTENDED [[gnu::fallthrough]]
121 #endif
122 
123 #ifndef OTABSL_FALLTHROUGH_INTENDED
124 #define OTABSL_FALLTHROUGH_INTENDED \
125  do { \
126  } while (0)
127 #endif
128 
129 // OTABSL_DEPRECATED()
130 //
131 // Marks a deprecated class, struct, enum, function, method and variable
132 // declarations. The macro argument is used as a custom diagnostic message (e.g.
133 // suggestion of a better alternative).
134 //
135 // Examples:
136 //
137 // class OTABSL_DEPRECATED("Use Bar instead") Foo {...};
138 //
139 // OTABSL_DEPRECATED("Use Baz() instead") void Bar() {...}
140 //
141 // template <typename T>
142 // OTABSL_DEPRECATED("Use DoThat() instead")
143 // void DoThis();
144 //
145 // Every usage of a deprecated entity will trigger a warning when compiled with
146 // clang's `-Wdeprecated-declarations` option. This option is turned off by
147 // default, but the warnings will be reported by clang-tidy.
148 #if defined(__clang__) && __cplusplus >= 201103L
149 #define OTABSL_DEPRECATED(message) __attribute__((deprecated(message)))
150 #endif
151 
152 #ifndef OTABSL_DEPRECATED
153 #define OTABSL_DEPRECATED(message)
154 #endif
155 
156 // OTABSL_BAD_CALL_IF()
157 //
158 // Used on a function overload to trap bad calls: any call that matches the
159 // overload will cause a compile-time error. This macro uses a clang-specific
160 // "enable_if" attribute, as described at
161 // https://clang.llvm.org/docs/AttributeReference.html#enable-if
162 //
163 // Overloads which use this macro should be bracketed by
164 // `#ifdef OTABSL_BAD_CALL_IF`.
165 //
166 // Example:
167 //
168 // int isdigit(int c);
169 // #ifdef OTABSL_BAD_CALL_IF
170 // int isdigit(int c)
171 // OTABSL_BAD_CALL_IF(c <= -1 || c > 255,
172 // "'c' must have the value of an unsigned char or EOF");
173 // #endif // OTABSL_BAD_CALL_IF
174 #if OTABSL_HAVE_ATTRIBUTE(enable_if)
175 #define OTABSL_BAD_CALL_IF(expr, msg) \
176  __attribute__((enable_if(expr, "Bad call trap"), unavailable(msg)))
177 #endif
178 
179 // OTABSL_ASSERT()
180 //
181 // In C++11, `assert` can't be used portably within constexpr functions.
182 // OTABSL_ASSERT functions as a runtime assert but works in C++11 constexpr
183 // functions. Example:
184 //
185 // constexpr double Divide(double a, double b) {
186 // return OTABSL_ASSERT(b != 0), a / b;
187 // }
188 //
189 // This macro is inspired by
190 // https://akrzemi1.wordpress.com/2017/05/18/asserts-in-constexpr-functions/
191 #if defined(NDEBUG)
192 #define OTABSL_ASSERT(expr) \
193  (false ? static_cast<void>(expr) : static_cast<void>(0))
194 #else
195 #define OTABSL_ASSERT(expr) \
196  (OTABSL_PREDICT_TRUE((expr)) ? static_cast<void>(0) \
197  : [] { assert(false && #expr); }()) // NOLINT
198 #endif
199 
200 #ifdef OTABSL_HAVE_EXCEPTIONS
201 #define OTABSL_INTERNAL_TRY try
202 #define OTABSL_INTERNAL_CATCH_ANY catch (...)
203 #define OTABSL_INTERNAL_RETHROW do { throw; } while (false)
204 #else // OTABSL_HAVE_EXCEPTIONS
205 #define OTABSL_INTERNAL_TRY if (true)
206 #define OTABSL_INTERNAL_CATCH_ANY else if (false)
207 #define OTABSL_INTERNAL_RETHROW do {} while (false)
208 #endif // OTABSL_HAVE_EXCEPTIONS
209 
210 #endif // OTABSL_BASE_MACROS_H_
absl::base_internal::kLinkerInitialized
@ kLinkerInitialized
Definition: includes/opentelemetry/nostd/internal/absl/base/macros.h:71
port.h
OTABSL_NAMESPACE_BEGIN
#define OTABSL_NAMESPACE_BEGIN
Definition: includes/opentelemetry/nostd/internal/absl/base/config.h:91
absl::base_internal::LinkerInitialized
LinkerInitialized
Definition: includes/opentelemetry/nostd/internal/absl/base/macros.h:70
attributes.h
absl::macros_internal::ArraySizeHelper
auto ArraySizeHelper(const T(&array)[N]) -> char(&)[N]
absl
Definition: includes/opentelemetry/nostd/variant.h:54
OTABSL_NAMESPACE_END
#define OTABSL_NAMESPACE_END
Definition: includes/opentelemetry/nostd/internal/absl/base/config.h:92
optimization.h