DART 6.13.2
Loading...
Searching...
No Matches
Macros.hpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011-2022, The DART development contributors
3 * All rights reserved.
4 *
5 * The list of contributors can be found at:
6 * https://github.com/dartsim/dart/blob/master/LICENSE
7 *
8 * This file is provided under the following "BSD-style" License:
9 * Redistribution and use in source and binary forms, with or
10 * without modification, are permitted provided that the following
11 * conditions are met:
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer in the documentation and/or other materials provided
17 * with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
19 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
20 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
23 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
26 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
29 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33#ifndef DART_COMMON_MACROS_HPP_
34#define DART_COMMON_MACROS_HPP_
35
36#include <cassert>
37
39
40// DART_NUM_ARGS(<arg1> [, <arg2> [, ...]])
41#define DETAIL_DART_NUM_ARGS(z, a, b, c, d, e, f, cnt, ...) cnt
42#define DART_NUM_ARGS(...) \
43 DETAIL_DART_NUM_ARGS(, ##__VA_ARGS__, 6, 5, 4, 3, 2, 1, 0)
44
45// DART_CONCAT(a, b)
46#define DETAIL_DART_CONCAT(a, b) a##b
47#define DART_CONCAT(a, b) DETAIL_DART_CONCAT(a, b)
48
49// Macro to suppress -Wunused-parameter and -Wunused-variable warnings in
50// release mode when a variable is only used in assertions.
51//
52// Usage: DART_UNUSED(<variable1> [, <variable2> [, ...]])
53#define DETAIL_DART_UNUSED_0()
54#define DETAIL_DART_UNUSED_1(a) (void)(a)
55#define DETAIL_DART_UNUSED_2(a, b) (void)(a), DETAIL_DART_UNUSED_1(b)
56#define DETAIL_DART_UNUSED_3(a, b, c) (void)(a), DETAIL_DART_UNUSED_2(b, c)
57#define DETAIL_DART_UNUSED_4(a, b, c, d) \
58 (void)(a), DETAIL_DART_UNUSED_3(b, c, d)
59#define DETAIL_DART_UNUSED_5(a, b, c, d, e) \
60 (void)(a), DETAIL_DART_UNUSED_4(b, c, d, e)
61#define DETAIL_DART_UNUSED_6(a, b, c, d, e, f) \
62 (void)(a), DETAIL_DART_UNUSED_5(b, c, d, e, f)
63#define DART_UNUSED(...) \
64 DART_CONCAT(DETAIL_DART_UNUSED_, DART_NUM_ARGS(__VA_ARGS__))(__VA_ARGS__)
65
66// DART_ASSERT(<expression> [, <message>])
67#define DETAIL_DART_ASSERT_1(condition) assert(condition)
68#define DETAIL_DART_ASSERT_2(condition, message) assert((condition) && #message)
69#define DART_ASSERT(...) \
70 DART_CONCAT(DETAIL_DART_ASSERT_, DART_NUM_ARGS(__VA_ARGS__)) \
71 (__VA_ARGS__)
72
73// Macro to mark the function is not implemented
74#define DART_NOT_IMPLEMENTED \
75 DART_FATAL("Not implemented: {}:{}", __FILE__, __LINE__); \
76 void(0)
77
78#endif