VTK
vtkAssume.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Visualization Toolkit
4  Module: vtkAssume.h
5 
6  Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7  All rights reserved.
8  See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9 
10  This software is distributed WITHOUT ANY WARRANTY; without even
11  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12  PURPOSE. See the above copyright notice for more information.
13 
14 =========================================================================*/
20 #ifndef vtkAssume_h
21 #define vtkAssume_h
22 
23 #include "vtkConfigure.h"
24 
25 #include <cassert>
26 
42 #define VTK_ASSUME(cond) \
43  do \
44  { \
45  const bool c = cond; \
46  assert("Bad assumption in VTK_ASSUME: " #cond&& c); \
47  VTK_ASSUME_IMPL(c); \
48  (void)c; /* Prevents unused var warnings */ \
49  } while (false) /* do-while prevents extra semicolon warnings */
50 
51 #define VTK_ASSUME_NO_ASSERT(cond) \
52  do \
53  { \
54  const bool c = cond; \
55  VTK_ASSUME_IMPL(c); \
56  (void)c; /* Prevents unused var warnings */ \
57  } while (false) /* do-while prevents extra semicolon warnings */
58 
59 // VTK_ASSUME_IMPL is compiler-specific:
60 #if defined(VTK_COMPILER_MSVC) || defined(VTK_COMPILER_ICC)
61 #define VTK_ASSUME_IMPL(cond) __assume(cond)
62 #elif defined(VTK_COMPILER_GCC) || defined(VTK_COMPILER_CLANG)
63 #define VTK_ASSUME_IMPL(cond) \
64  if (!(cond)) \
65  __builtin_unreachable()
66 #else
67 #define VTK_ASSUME_IMPL(cond) \
68  do \
69  { \
70  } while (false) /* no-op */
71 #endif
72 
73 #endif // vtkAssume_h
74 // VTK-HeaderTest-Exclude: vtkAssume.h