summaryrefslogtreecommitdiffhomepage
path: root/compat/macros.hpp
blob: 89e095dde79a03ad41b4573c208a5181a14f4fd1 (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
#pragma once

#include "macros1.h"

#ifdef __cplusplus

// from now only C++

#include <utility>
#include <type_traits>

// before C++20
namespace cxx20_compat {
    template<typename T>
    struct remove_cvref {
        using type = std::remove_cv_t<std::remove_reference_t<T>>;
    };
} // ns cxx20_compat

template<typename t>
using remove_cvref_t = typename cxx20_compat::remove_cvref<t>::type;

template<typename t>
using to_const_cvref_t = std::add_lvalue_reference_t<std::add_const_t<remove_cvref_t<t>>>;

// causes ICE in Visual Studio 2017 Preview. the ICE was reported and they handle them seriously in due time.
// the ICE is caused by decltype(auto) and const& return value
//#define eval_once(expr) ([&]() -> decltype(auto) { static decltype(auto) ret___1132 = (expr); return (decltype(ret___1132) const&) ret___1132; }())

#define eval_once(expr) eval_once2(expr, __COUNTER__)

#define eval_once2(expr, ctr)                                       \
    ([&] {                                                          \
        [[maybe_unused]]                                            \
        static auto PP_CAT(eval_once_, ctr) = (((void)(expr)), 0);  \
    }())

template<typename t>
using cv_qualified = std::conditional_t<std::is_fundamental_v<remove_cvref_t<t>>,
                                        remove_cvref_t<t>,
                                        to_const_cvref_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(...) ([&]() -> decltype(auto) { __VA_ARGS__ }())

// end c++-only macros
#endif