Rigid Body Dynamics Library
compileassert.h
Go to the documentation of this file.
1/*
2 * RBDL - Rigid Body Dynamics Library
3 * Copyright (c) 2011-2018 Martin Felis <martin@fysx.org>
4 *
5 * Licensed under the zlib license. See LICENSE for more details.
6 */
7
8#ifndef RBDL_COMPILE_ASSERT_H
9#define RBDL_COMPILE_ASSERT_H
10
11/*
12 * This is a simple compile time assertion tool taken from:
13 * http://blogs.msdn.com/b/abhinaba/archive/2008/10/27/c-c-compile-time-asserts.aspx
14 * written by Abhinaba Basu!
15 *
16 * Thanks!
17 */
18
19#ifdef __cplusplus
20
21#define JOIN( X, Y ) JOIN2(X,Y)
22#define JOIN2( X, Y ) X##Y
23
25{
26template <bool> struct STATIC_ASSERT_FAILURE;
27template <> struct STATIC_ASSERT_FAILURE<true> { enum { value = 1 }; };
28
29template<int x> struct custom_static_assert_test{};
30}
31
32#define COMPILE_ASSERT(x) \
33 typedef ::custom_static_assert::custom_static_assert_test<\
34sizeof(::custom_static_assert::STATIC_ASSERT_FAILURE< (bool)( x ) >)>\
35JOIN(_custom_static_assert_typedef, __LINE__)
36
37#else // __cplusplus
38
39#define COMPILE_ASSERT(x) extern int __dummy[(int)x]
40
41#endif // __cplusplus
42
43#define VERIFY_EXPLICIT_CAST(from, to) COMPILE_ASSERT(sizeof(from) == sizeof(to))
44
45// RBDL_COMPILE_ASSERT_H_
46#endif