VTK  9.5.20251004
Macros
vtkAssume.h File Reference
#include "vtkCompiler.h"
#include <cassert>
Include dependency graph for vtkAssume.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define VTK_ASSUME(cond)
 VTK_ASSUME instructs the compiler that a certain non-obvious condition will always be true.
 
#define VTK_ASSUME_NO_ASSERT(cond)
 
#define VTK_HAS_BUILTIN(x)   0
 
#define VTK_ASSUME_IMPL(cond)
 
#define VTK_EXPECT(cond, expected)   (cond)
 
#define VTK_LIKELY(cond)   (cond)
 
#define VTK_UNLIKELY(cond)   (cond)
 

Macro Definition Documentation

◆ VTK_ASSUME

#define VTK_ASSUME (   cond)
Value:
do \
{ \
const bool c = cond; \
assert("Bad assumption in VTK_ASSUME: " #cond&& c); \
VTK_ASSUME_IMPL(c); \
(void)c; /* Prevents unused var warnings */ \
} while (false) /* do-while prevents extra semicolon warnings */

VTK_ASSUME instructs the compiler that a certain non-obvious condition will always be true.

Beware that if cond is false at runtime, the results are unpredictable (and likely catastrophic). A runtime assertion is added so that debugging builds may easily catch violations of the condition.

A useful application of this macro is when a vtkGenericDataArray subclass has a known number of components at compile time. Adding, for example, VTK_ASSUME(array->GetNumberOfComponents() == 3); allows the compiler to provide faster access through the GetTypedComponent method, as the fixed data stride in AOS arrays allows advanced optimization of the accesses.

A more detailed description of this class and related tools can be found here.

Definition at line 30 of file vtkAssume.h.

◆ VTK_ASSUME_NO_ASSERT

#define VTK_ASSUME_NO_ASSERT (   cond)
Value:
do \
{ \
const bool c = cond; \
VTK_ASSUME_IMPL(c); \
(void)c; /* Prevents unused var warnings */ \
} while (false) /* do-while prevents extra semicolon warnings */

Definition at line 39 of file vtkAssume.h.

◆ VTK_HAS_BUILTIN

#define VTK_HAS_BUILTIN (   x)    0

Definition at line 50 of file vtkAssume.h.

◆ VTK_ASSUME_IMPL

#define VTK_ASSUME_IMPL (   cond)
Value:
do \
{ \
} while (false) /* no-op */

Definition at line 65 of file vtkAssume.h.

◆ VTK_EXPECT

#define VTK_EXPECT (   cond,
  expected 
)    (cond)

Definition at line 77 of file vtkAssume.h.

◆ VTK_LIKELY

#define VTK_LIKELY (   cond)    (cond)

Definition at line 78 of file vtkAssume.h.

◆ VTK_UNLIKELY

#define VTK_UNLIKELY (   cond)    (cond)

Definition at line 79 of file vtkAssume.h.