1 | // |
2 | // immer: immutable data structures for C++ |
3 | // Copyright (C) 2016, 2017, 2018 Juan Pedro Bolivar Puente |
4 | // |
5 | // This software is distributed under the Boost Software License, Version 1.0. |
6 | // See accompanying file LICENSE or copy at http://boost.org/LICENSE_1_0.txt |
7 | // |
8 | |
9 | #pragma once |
10 | |
11 | #if defined(__has_cpp_attribute) |
12 | #if __has_cpp_attribute(nodiscard) |
13 | #define IMMER_NODISCARD [[nodiscard]] |
14 | #endif |
15 | #else |
16 | #if _MSVC_LANG >= 201703L |
17 | #define IMMER_NODISCARD [[nodiscard]] |
18 | #endif |
19 | #endif |
20 | |
21 | #ifndef IMMER_NODISCARD |
22 | #define IMMER_NODISCARD |
23 | #endif |
24 | |
25 | #ifndef IMMER_TAGGED_NODE |
26 | #ifdef NDEBUG |
27 | #define IMMER_TAGGED_NODE 0 |
28 | #else |
29 | #define IMMER_TAGGED_NODE 1 |
30 | #endif |
31 | #endif |
32 | |
33 | #if IMMER_TAGGED_NODE |
34 | #define IMMER_ASSERT_TAGGED(assertion) assert(assertion) |
35 | #else |
36 | #define IMMER_ASSERT_TAGGED(assertion) |
37 | #endif |
38 | |
39 | #ifndef IMMER_DEBUG_TRACES |
40 | #define IMMER_DEBUG_TRACES 0 |
41 | #endif |
42 | |
43 | #ifndef IMMER_DEBUG_PRINT |
44 | #define IMMER_DEBUG_PRINT 0 |
45 | #endif |
46 | |
47 | #ifndef IMMER_DEBUG_DEEP_CHECK |
48 | #define IMMER_DEBUG_DEEP_CHECK 0 |
49 | #endif |
50 | |
51 | #if IMMER_DEBUG_TRACES || IMMER_DEBUG_PRINT |
52 | #include <iostream> |
53 | #include <prettyprint.hpp> |
54 | #endif |
55 | |
56 | #if IMMER_DEBUG_TRACES |
57 | #define IMMER_TRACE(...) std::cout << __VA_ARGS__ << std::endl |
58 | #else |
59 | #define IMMER_TRACE(...) |
60 | #endif |
61 | #define IMMER_TRACE_F(...) \ |
62 | IMMER_TRACE(__FILE__ << ":" << __LINE__ << ": " << __VA_ARGS__) |
63 | #define IMMER_TRACE_E(expr) \ |
64 | IMMER_TRACE(" " << #expr << " = " << (expr)) |
65 | |
66 | #if defined(_MSC_VER) |
67 | #define IMMER_UNREACHABLE __assume(false) |
68 | #define IMMER_LIKELY(cond) cond |
69 | #define IMMER_UNLIKELY(cond) cond |
70 | #define IMMER_FORCEINLINE __forceinline |
71 | #define IMMER_PREFETCH(p) |
72 | #else |
73 | #define IMMER_UNREACHABLE __builtin_unreachable() |
74 | #define IMMER_LIKELY(cond) __builtin_expect(!!(cond), 1) |
75 | #define IMMER_UNLIKELY(cond) __builtin_expect(!!(cond), 0) |
76 | #define IMMER_FORCEINLINE inline __attribute__ ((always_inline)) |
77 | #define IMMER_PREFETCH(p) |
78 | // #define IMMER_PREFETCH(p) __builtin_prefetch(p) |
79 | #endif |
80 | |
81 | #define IMMER_DESCENT_DEEP 0 |
82 | |
83 | #ifdef NDEBUG |
84 | #define IMMER_ENABLE_DEBUG_SIZE_HEAP 0 |
85 | #else |
86 | #define IMMER_ENABLE_DEBUG_SIZE_HEAP 1 |
87 | #endif |
88 | |
89 | namespace immer { |
90 | |
91 | const auto default_bits = 5; |
92 | const auto default_free_list_size = 1 << 10; |
93 | |
94 | } // namespace immer |
95 | |