qxLib
common.h
Go to the documentation of this file.
1 /**
2 
3  @file common.h
4  @author Khrapov
5  @date 17.06.2019
6  @copyright © Nick Khrapov, 2021. All right reserved.
7 
8 **/
9 #pragma once
10 
12 #include <qx/meta/qualifiers.h>
13 
14 #include <qx/macros/common.inl>
15 
16 /**
17  @brief Suppress unused variable warnings
18  @param ... - one or more variables
19 **/
20 #define QX_UNUSED(...) ((void)sizeof(__VA_ARGS__))
21 
22 /**
23  @def QX_EMPTY_MACRO
24  @brief Placeholder for disabled macros
25  @details Has no effect and work correctly with "if else"
26  You can use it in the end of a macro to enforce user to add ; after it
27 **/
28 #define QX_EMPTY_MACRO static_assert(true)
29 
30 /**
31  @brief Concatenates two preprocessor tokens, performing macro expansion on them first
32 **/
33 #define QX_JOIN(symbol1, symbol2) _QX_DO_JOIN(symbol1, symbol2)
34 
35 /**
36  @brief Same as __LINE__, but fixes some problems when using it in constexpr context
37 **/
38 #define QX_LINE int(QX_JOIN(__LINE__, U))
39 
40 /**
41  @def QX_SHORT_FILE
42  @brief Cuts full absolute path to the file name only
43  ex: "C:\folder1\folder2\file.h" => "file.h"
44 **/
45 #define QX_SHORT_FILE qx::details::last_slash(QXT(__FILE__))
46 
47 /**
48  @def QX_CONST_CAST_THIS
49  @brief This macro is made for situations where you have a const method, and you need exactly the same method but non-const
50  @warning You can also use it in vice versa situations, but be careful as it will break your const guarantees
51 
52  @code
53  int foo() const
54  {
55  // some complicated stuff
56  }
57  int foo()
58  {
59  QX_CONST_CAST_THIS()->foo();
60  }
61  @endcode
62 **/
63 #define QX_CONST_CAST_THIS() const_cast<qx::switch_const_t<std::remove_pointer_t<decltype(this)>>*>(this)
64 
65 /**
66  @def QX_CALL_BEFORE_MAIN
67  @brief Calls this lambda before the main invocation
68  @note This function must be in an object file, that is actually linked to your exe
69 
70  @code
71  QX_CALL_BEFORE_MAIN = []()
72  {
73  };
74  @endcode
75 **/
76 #define QX_CALL_BEFORE_MAIN inline volatile qx::details::call_before_main_invoker QX_LINE_NAME(_stubCallBeforeMain)
77 
78 /**
79  @brief Start a block with compiling optimisations disabled.
80  Must be outside of functions and have an appropriate QX_ENABLE_OPTIMIZATIONS().
81 **/
82 #define QX_DISABLE_OPTIMIZATIONS() _QX_DISABLE_OPTIMIZATIONS()
83 
84 /**
85  @brief End a block with compiling optimisations disabled.
86 **/
87 #define QX_ENABLE_OPTIMIZATIONS() _QX_ENABLE_OPTIMIZATIONS()
88 
89 /**
90  @brief Make this function forcefully inlined (except for QX_DEBUG build)
91 **/
92 #define QX_FORCE_INLINE _QX_FORCE_INLINE
93 
94 /**
95  @brief Add __VA_ARGS__ count to the preprocessor prefix
96  @details It supports up to 32 arguments, ranging from 0 (empty parentheses).
97  @param prefix - preprocessor prefix
98  @param ... - va args to count
99  @code
100  QX_APPEND_VA_ARG_COUNT(foo_, 1, 1, 1); // -> foo_3
101  @endcode
102 **/
103 #define QX_APPEND_VA_ARG_COUNT(prefix, ...) _QX_APPEND_VA_ARG_COUNT(prefix, ##__VA_ARGS__)
104 
105 /**
106  @brief Get number of va args
107  @details It supports up to 32 arguments, ranging from 0 (empty parentheses).
108  @param ... - va args to count
109  @code
110  QX_VA_ARG_COUNT(1, 1, 1); // -> 3
111  @endcode
112 **/
113 #define QX_VA_ARG_COUNT(...) QX_APPEND_VA_ARG_COUNT(, ##__VA_ARGS__)
114 
115 /**
116  @brief Forces an extra macro expansion step so that a macro result is fully resolved before being used as a function-like macro.
117 **/
118 #define QX_EXPAND(x) x