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 Same as __LINE__, but fixes some problems when using it in constexpr context
26 **/
27 #define QX_LINE int(_QX_JOIN(__LINE__, U))
28 
29 /**
30  @def QX_SHORT_FILE
31  @brief Cuts full absolute path to the file name only
32  ex: "C:\folder1\foler2\file.h" => "file.h"
33 **/
34 #define QX_SHORT_FILE qx::details::last_slash(QX_TEXT(__FILE__))
35 
36 /**
37  @def QX_SINGLE_ARGUMENT
38  @brief Let macro param containing commas work fine
39  "#define FOO(type, name) type name"
40  FOO(QX_SINGLE_ARGUMENT(std::map<int, int>), map_var);
41  @param ... - param containing commas
42 **/
43 #define QX_SINGLE_ARGUMENT(...) __VA_ARGS__
44 
45 /**
46  @def QX_CONST_CAST_THIS
47  @brief This macro is made for situations where you have a const method and you need exactly the same method but non-const
48  @warning You can also use it in vice-versa situations, but be careful as it will break your const guarantees
49 
50  @code
51  int foo() const
52  {
53  // some complicated stuff
54  }
55  int foo()
56  {
57  QX_CONST_CAST_THIS()->foo();
58  }
59  @endcode
60 **/
61 #define QX_CONST_CAST_THIS() const_cast<qx::switch_const_t<std::remove_pointer_t<decltype(this)>>*>(this)
62 
63 /**
64  @def QX_CALL_BEFORE_MAIN
65  @brief Calls this lambda before the main invocation
66  @note This function must be in an object file, that is actually linked to your exe
67 
68  @code
69  QX_CALL_BEFORE_MAIN = []()
70  {
71  };
72  @endcode
73 **/
74 #define QX_CALL_BEFORE_MAIN inline volatile qx::details::call_before_main_invoker QX_LINE_NAME(_stubCallBeforeMain)
75 
76 /**
77  @brief Start a block with compiling optimisations disabled.
78  Must be outside of functions and have an appropriate QX_ENABLE_OPTIMIZATIONS().
79 **/
80 #define QX_DISABLE_OPTIMIZATIONS() _QX_DISABLE_OPTIMIZATIONS()
81 
82 /**
83  @brief End a block with compiling optimisations disabled.
84 **/
85 #define QX_ENABLE_OPTIMIZATIONS() _QX_ENABLE_OPTIMIZATIONS()
86 
87 /**
88  @brief Make this function forcefully inlined (except for QX_DEBUG build)
89 **/
90 #define QX_FORCE_INLINE _QX_FORCE_INLINE