MRPT  1.9.9
xassert.h
Go to the documentation of this file.
1 /* +------------------------------------------------------------------------+
2  | Mobile Robot Programming Toolkit (MRPT) |
3  | http://www.mrpt.org/ |
4  | |
5  | Copyright (c) 2005-2018, Individual contributors, see AUTHORS file |
6  | See: http://www.mrpt.org/Authors - All rights reserved. |
7  | Released under BSD License. See details in http://www.mrpt.org/License |
8  +------------------------------------------------------------------------+ */
9 #pragma once
10 
11 #include <stdexcept>
12 
13 /** MRPT_LIKELY(): disable the branch prediction and manually setting the
14  * preference
15  * for the positive case.
16  * See:
17  * https://akrzemi1.wordpress.com/2017/05/18/asserts-in-constexpr-functions */
18 #if defined __GNUC__
19 #define MRPT_LIKELY(EXPR) __builtin_expect(!!(EXPR), 1)
20 #else
21 #define MRPT_LIKELY(EXPR) (!!(EXPR))
22 #endif
23 
24 /** MRPT_X_ASSERT(): build error if condition is known not to work at compile
25  * time, throw an exception at runtime if the condition needs to be evaluated.
26  */
27 #define MRPT_X_ASSERT(CHECK) \
28  (MRPT_LIKELY(CHECK) ? void(0) : [] { throw std::runtime_error(#CHECK); }())



Page generated by Doxygen 1.8.14 for MRPT 1.9.9 Git: 7d5e6d718 Fri Aug 24 01:51:28 2018 +0200 at lun nov 2 08:35:50 CET 2020