Math API nvidia_logo_transpbg.gif Up
assert.h
Go to the documentation of this file.
1/***************************************************************************************************
2 * Copyright 2023 NVIDIA Corporation. All rights reserved.
3 **************************************************************************************************/
8
9#ifndef MI_BASE_ASSERT_H
10#define MI_BASE_ASSERT_H
11
12#include <mi/base/config.h>
13
14namespace mi {
15
16namespace base {
17
52#ifndef mi_static_assert
53#ifdef _MSC_VER
54// Special case for Visual Studio 7.1, since __LINE__ would not work.
55#define mi_static_assert(expr) \
56 typedef mi::base::static_assert_test<static_cast<int>( \
57 sizeof(mi::base::static_assert_failure<static_cast<bool>((expr))>))> \
58 MI_BASE_JOIN(static_assert_instance, __COUNTER__)
59#else // _MSC_VER
60#ifdef MI_COMPILER_GCC
61#define mi_static_assert_attribute __attribute__((unused))
62#else
63#define mi_static_assert_attribute
64#endif
65#define mi_static_assert(expr) \
66 typedef mi::base::static_assert_test<static_cast<int>( \
67 sizeof(mi::base::static_assert_failure<static_cast<bool>((expr))>))> \
68 MI_BASE_JOIN(static_assert_instance, __LINE__) mi_static_assert_attribute
69#endif // _MSC_VER
70#endif // mi_static_assert
71
72// helper definitions for the mi_static_assert above.
73template <bool> struct static_assert_failure;
74template <> struct static_assert_failure<true> {};
75template <int> struct static_assert_test {};
76
77#if defined( mi_base_assert) && ! defined( mi_base_assert_msg) \
78 || ! defined( mi_base_assert) && defined( mi_base_assert_msg)
79error "Only one of mi_base_assert and mi_base_assert_msg has been defined. Please define both."
80#else
81#ifndef mi_base_assert
82
94#define mi_base_assert(expr) (static_cast<void>(0)) // valid but void null stmt
95
111#define mi_base_assert_msg(expr, msg) (static_cast<void>(0)) // valid but void null stmt
112
113// Just for doxygen, begin
114
119#define mi_base_assert_enabled
120#undef mi_base_assert_enabled
121
122// Just for doxygen, end
123
124#else // mi_base_assert
125
126#define mi_base_assert_enabled
127
128#endif // mi_base_assert
129#endif // mi_base_assert xor mi_base_assert_msg
130
140#if defined(__FUNCSIG__)
141# define MI_BASE_ASSERT_FUNCTION __FUNCSIG__
142#elif defined( __cplusplus) && defined(__GNUC__) && defined(__GNUC_MINOR__) \
143 && ((__GNUC__ << 16) + __GNUC_MINOR__ >= (2 << 16) + 6)
144# define MI_BASE_ASSERT_FUNCTION __PRETTY_FUNCTION__
145#else
146# if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
147# define MI_BASE_ASSERT_FUNCTION __func__
148# else
149# define MI_BASE_ASSERT_FUNCTION ("unknown")
150# endif
151#endif
152 // end group mi_base_assert
154
155} // namespace base
156
157} // namespace mi
158
159#endif // MI_BASE_ASSERT_H
Configuration of the Base API.
std::basic_ostream<C, T> & error(std::basic_ostream<C, T> &ostream)
Manipulator for mi::base::Log_stream.
Definition: ilogger.h:542
Common namespace for APIs of NVIDIA Advanced Rendering Center GmbH.
Definition: math.h:22