summaryrefslogtreecommitdiffhomepage
path: root/compat/macros.hpp
blob: 57883827b45c4c7bc713121eb0bbfdf932275c35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#pragma once

#if defined _MSC_VER
#   define MEMORY_BARRIER() _ReadWriteBarrier()
#else
#   define MEMORY_BARRIER() asm volatile("" ::: "memory")
#endif

#if defined _MSC_VER
#   define cc_noinline __declspec(noinline)
#elif defined __GNUG__
#   define cc_noinline __attribute__((noinline))
#else
#   define cc_noinline
#endif

#if defined _MSC_VER
#   define cc_forceinline __forceinline
#else
#   define cc_forceinline __attribute__((always_inline, gnu_inline)) inline
#endif

#ifdef Q_CREATOR_RUN
#   define cc_warn_unused_result
#elif defined _MSC_VER
#   define cc_warn_unused_result _Check_return_
#else
#   define cc_warn_unused_result __attribute__((warn_unused_result))
#endif

#if !defined likely
#   if defined __GNUC__
#      define likely(x)       __builtin_expect(!!(x),1)
#      define unlikely(x)     __builtin_expect(!!(x),0)
#   else
#      define likely(x) (x)
#      define unlikely(x) (x)
#   endif
#endif

#if defined _MSC_VER
#   define cc_function_name (__FUNCSIG__)
#else
#   define cc_function_name (__PRETTY_FUNCTION__)
#endif

#if !defined PP_CAT
#   define PP_CAT(x,y) PP_CAT1(x,y)
#   define PP_CAT1(x,y) x##y
#endif

#define once_only(...) do { static bool once__ = false; if (!once__) { once__ = true; __VA_ARGS__; } } while(false)

#if defined __cplusplus

// from now only C++

#include <type_traits>

template<typename t>
using cv_qualified = std::conditional_t<std::is_fundamental_v<std::decay_t<t>>,
                                        std::decay_t<t>,
                                        std::add_lvalue_reference_t<std::add_const_t<std::remove_reference_t<t>>>>;

template<bool>
[[deprecated]] constexpr cc_forceinline void static_warn() {}

template<>
constexpr cc_forceinline void static_warn<true>() {}

#define static_warning(cond)            \
        static_warn<(cond)>();          \

#define progn(...) (([&] { __VA_ARGS__ })())
#define prog1(x, ...) (([&] { auto _ret1324 = (x); do { __VA_ARGS__; } while (0); return _ret1324; })())

// end c++-only macros
#endif