about summary refs log tree commit diff
path: root/immer/config.hpp
blob: 581e905a4de39c640bff8f384b716ad138df9d8e (plain) (blame)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
//
// immer: immutable data structures for C++
// Copyright (C) 2016, 2017, 2018 Juan Pedro Bolivar Puente
//
// This software is distributed under the Boost Software License, Version 1.0.
// See accompanying file LICENSE or copy at http://boost.org/LICENSE_1_0.txt
//

#pragma once

#if defined(__has_cpp_attribute)
#if __has_cpp_attribute(nodiscard)
#define IMMER_NODISCARD [[nodiscard]]
#endif
#else
#if _MSVC_LANG >= 201703L
#define IMMER_NODISCARD [[nodiscard]]
#endif
#endif

#ifndef IMMER_NODISCARD
#define IMMER_NODISCARD
#endif

#ifndef IMMER_TAGGED_NODE
#ifdef NDEBUG
#define IMMER_TAGGED_NODE 0
#else
#define IMMER_TAGGED_NODE 1
#endif
#endif

#if IMMER_TAGGED_NODE
#define IMMER_ASSERT_TAGGED(assertion) assert(assertion)
#else
#define IMMER_ASSERT_TAGGED(assertion)
#endif

#ifndef IMMER_DEBUG_TRACES
#define IMMER_DEBUG_TRACES 0
#endif

#ifndef IMMER_DEBUG_PRINT
#define IMMER_DEBUG_PRINT 0
#endif

#ifndef IMMER_DEBUG_DEEP_CHECK
#define IMMER_DEBUG_DEEP_CHECK 0
#endif

#if IMMER_DEBUG_TRACES || IMMER_DEBUG_PRINT
#include <iostream>
#include <prettyprint.hpp>
#endif

#if IMMER_DEBUG_TRACES
#define IMMER_TRACE(...) std::cout << __VA_ARGS__ << std::endl
#else
#define IMMER_TRACE(...)
#endif
#define IMMER_TRACE_F(...)                                                     \
    IMMER_TRACE(__FILE__ << ":" << __LINE__ << ": " << __VA_ARGS__)
#define IMMER_TRACE_E(expr) IMMER_TRACE("    " << #expr << " = " << (expr))

#if defined(_MSC_VER)
#define IMMER_UNREACHABLE __assume(false)
#define IMMER_LIKELY(cond) cond
#define IMMER_UNLIKELY(cond) cond
#define IMMER_FORCEINLINE __forceinline
#define IMMER_PREFETCH(p)
#else
#define IMMER_UNREACHABLE __builtin_unreachable()
#define IMMER_LIKELY(cond) __builtin_expect(!!(cond), 1)
#define IMMER_UNLIKELY(cond) __builtin_expect(!!(cond), 0)
#define IMMER_FORCEINLINE inline __attribute__((always_inline))
#define IMMER_PREFETCH(p)
// #define IMMER_PREFETCH(p)    __builtin_prefetch(p)
#endif

#define IMMER_DESCENT_DEEP 0

#ifdef NDEBUG
#define IMMER_ENABLE_DEBUG_SIZE_HEAP 0
#else
#define IMMER_ENABLE_DEBUG_SIZE_HEAP 1
#endif

namespace immer {

const auto default_bits           = 5;
const auto default_free_list_size = 1 << 10;

} // namespace immer