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