proxsuite
0.7.3
The Advanced Proximal Optimization Toolbox
Toggle main menu visibility
Loading...
Searching...
No Matches
alloc.hpp
Go to the documentation of this file.
1
#ifndef VEG_ALLOC_HPP_QHYOV5XDS
2
#define VEG_ALLOC_HPP_QHYOV5XDS
3
4
#include "
proxsuite/linalg/veg/internal/has_asan.hpp
"
5
#include "
proxsuite/linalg/veg/ref.hpp
"
6
#include "
proxsuite/linalg/veg/type_traits/constructible.hpp
"
7
#include "
proxsuite/linalg/veg/type_traits/assignable.hpp
"
8
#include "
proxsuite/linalg/veg/internal/typedefs.hpp
"
9
#include "
proxsuite/linalg/veg/internal/macros.hpp
"
10
#include "
proxsuite/linalg/veg/memory/placement.hpp
"
11
#include "
proxsuite/linalg/veg/internal/prologue.hpp
"
12
#include <cstring>
13
14
namespace
proxsuite
{
15
namespace
linalg
{
16
namespace
veg
{
17
namespace
mem
{
18
template
<
typename
T>
19
struct
Alloc
20
{};
21
template
<
typename
T>
22
struct
Cloner
23
{};
24
}
// namespace mem
25
namespace
_detail
{
26
27
#if VEG_HAS_ASAN
28
extern
"C"
void
__sanitizer_annotate_contiguous_container
/* NOLINT */
(
29
const
void
* begin,
30
const
void
* end,
31
const
void
* old_mid,
32
const
void
* new_mid);
33
#endif
34
35
[[noreturn]]
HEDLEY_NEVER_INLINE
void
36
throw_bad_alloc
();
37
[[noreturn]]
inline
void
38
terminate
() noexcept;
39
namespace
_mem
{
40
struct
DeferUnreachable
/* NOLINT */
41
{
42
bool
is_unreachable
;
43
VEG_INLINE
~DeferUnreachable
()
44
{
45
if
(
is_unreachable
) {
46
HEDLEY_UNREACHABLE
();
47
}
48
}
49
};
50
}
// namespace _mem
51
}
// namespace _detail
52
53
namespace
mem {
54
inline
auto
55
memmove
(
void
* dest,
void
const
* src,
usize
nbytes)
noexcept
->
void
*
56
{
57
if
(dest !=
nullptr
) {
58
return
std::memmove(dest, src, nbytes);
59
}
else
{
60
return
dest;
61
}
62
}
63
64
using
byte
=
unsigned
char;
65
struct
AllocBlock
66
{
67
void
*
data
;
68
usize
byte_cap
;
69
};
70
struct
Layout
71
{
72
usize
byte_size
;
73
usize
align
;
74
};
75
struct
RelocFn
76
{
77
void
* (*fn)(
void
*,
void
const
*,
usize
);
78
79
VEG_INLINE
void
operator()
(
void
* dst,
void
* src,
usize
n)
const
noexcept
80
{
81
_detail::_mem::DeferUnreachable
_{
true
};
82
(*fn)(dst, src, n);
83
_.
is_unreachable
=
false
;
84
}
85
VEG_INLINE
auto
is_trivial
() const noexcept ->
bool
86
{
87
return
fn
== &
mem::memmove
;
88
}
89
};
90
}
// namespace mem
91
namespace
concepts {
92
namespace
alloc
{
93
VEG_CONCEPT_EXPR
((
typename
A),
94
(A),
95
dealloc,
96
mem::Alloc<A>::dealloc
(
//
97
VEG_DECLVAL
(
RefMut<A>
),
98
VEG_DECLVAL
(
void
*),
99
VEG_DECLVAL
(
mem::Layout
)),
100
true
);
101
102
VEG_CONCEPT_EXPR
((
typename
A),
103
(A),
104
alloc
,
105
mem::Alloc<A>::alloc
(
VEG_DECLVAL
(
RefMut<A>
),
106
VEG_DECLVAL
(
mem::Layout
)),
107
VEG_CONCEPT
(same<ExprType, mem::AllocBlock>));
108
109
VEG_CONCEPT_EXPR
((
typename
A),
110
(A),
111
owns_alloc,
112
mem::Alloc<A>::owns
(
VEG_DECLVAL
(
Ref<A>
),
113
VEG_DECLVAL
(
mem::Layout
)),
114
VEG_CONCEPT
(same<ExprType, bool>));
115
116
VEG_CONCEPT_EXPR
((
typename
A),
117
(A),
118
grow,
119
mem::Alloc<A>::grow
(
VEG_DECLVAL
(
RefMut<A>
),
120
VEG_DECLVAL
(
void
*),
121
VEG_DECLVAL
(
mem::Layout
),
122
VEG_DECLVAL
(
usize
),
123
VEG_DECLVAL
(
mem::RelocFn
)),
124
VEG_CONCEPT
(same<ExprType, mem::AllocBlock>));
125
126
VEG_CONCEPT_EXPR
((
typename
A),
127
(A),
128
shrink,
129
mem::Alloc<A>::shrink
(
VEG_DECLVAL
(
RefMut<A>
),
130
VEG_DECLVAL
(
void
*),
131
VEG_DECLVAL
(
mem::Layout
),
132
VEG_DECLVAL
(
usize
),
133
VEG_DECLVAL
(
mem::RelocFn
)),
134
VEG_CONCEPT
(same<ExprType, mem::AllocBlock>));
135
136
VEG_CONCEPT_EXPR
((
typename
C,
typename
T,
typename
A),
137
(C, T, A),
138
destroy,
139
mem::Cloner<C>::destroy
(
//
140
VEG_DECLVAL
(
RefMut<C>
),
141
VEG_DECLVAL
(T*),
142
VEG_DECLVAL
(
RefMut<A>
)),
143
true
);
144
145
VEG_CONCEPT_EXPR
((
typename
C,
typename
T,
typename
A),
146
(C, T, A),
147
clone,
148
mem::Cloner<C>::clone
(
//
149
VEG_DECLVAL
(
RefMut<C>
),
150
VEG_DECLVAL
(
Ref<T>
),
151
VEG_DECLVAL
(
RefMut<A>
)),
152
VEG_CONCEPT
(same<ExprType, T>));
153
154
VEG_CONCEPT_EXPR
((
typename
C,
typename
T,
typename
A),
155
(C, T, A),
156
clone_from,
157
mem::Cloner<C>::clone_from
(
VEG_DECLVAL
(
RefMut<C>
),
158
VEG_DECLVAL
(
RefMut<T>
),
159
VEG_DECLVAL
(
Ref<T>
),
160
VEG_DECLVAL
(
RefMut<A>
)),
161
true
);
162
}
// namespace alloc
163
}
// namespace concepts
164
}
// namespace veg
165
}
// namespace linalg
166
}
// namespace proxsuite
167
168
#include "
proxsuite/linalg/veg/internal/epilogue.hpp
"
169
#endif
/* end of include guard VEG_ALLOC_HPP_QHYOV5XDS */
assignable.hpp
constructible.hpp
epilogue.hpp
has_asan.hpp
HEDLEY_UNREACHABLE
#define HEDLEY_UNREACHABLE()
Definition
hedley.ext.hpp:1338
HEDLEY_NEVER_INLINE
#define HEDLEY_NEVER_INLINE
Definition
hedley.ext.hpp:1706
macros.hpp
VEG_CONCEPT_EXPR
#define VEG_CONCEPT_EXPR(Tpl, TplNames, Name, Expr,...)
Definition
macros.hpp:272
VEG_CONCEPT
#define VEG_CONCEPT(...)
Definition
macros.hpp:1238
VEG_INLINE
#define VEG_INLINE
Definition
macros.hpp:118
VEG_DECLVAL
#define VEG_DECLVAL(...)
Definition
macros.hpp:131
proxsuite::linalg::veg::_detail::_mem
Definition
address.hpp:25
proxsuite::linalg::veg::_detail
Definition
collection_algo.hpp:11
proxsuite::linalg::veg::_detail::terminate
void terminate() noexcept
Definition
terminate.hpp:12
proxsuite::linalg::veg::_detail::throw_bad_alloc
HEDLEY_NEVER_INLINE void throw_bad_alloc()
proxsuite::linalg::veg::concepts::alloc
Definition
alloc.hpp:92
proxsuite::linalg::veg::mem
Definition
address.hpp:72
proxsuite::linalg::veg::mem::byte
unsigned char byte
Definition
alloc.hpp:64
proxsuite::linalg::veg::mem::memmove
auto memmove(void *dest, void const *src, usize nbytes) noexcept -> void *
Definition
alloc.hpp:55
proxsuite::linalg::veg
Definition
collection_algo.hpp:10
proxsuite::linalg::veg::usize
decltype(sizeof(0)) usize
Definition
macros.hpp:699
proxsuite::linalg
Definition
core.hpp:85
proxsuite
Definition
common.hpp:14
placement.hpp
prologue.hpp
ref.hpp
proxsuite::linalg::veg::RefMut
Definition
ref.hpp:68
proxsuite::linalg::veg::Ref
Definition
ref.hpp:30
proxsuite::linalg::veg::_detail::_mem::DeferUnreachable
Definition
alloc.hpp:41
proxsuite::linalg::veg::_detail::_mem::DeferUnreachable::~DeferUnreachable
VEG_INLINE ~DeferUnreachable()
Definition
alloc.hpp:43
proxsuite::linalg::veg::_detail::_mem::DeferUnreachable::is_unreachable
bool is_unreachable
Definition
alloc.hpp:42
proxsuite::linalg::veg::mem::AllocBlock
Definition
alloc.hpp:66
proxsuite::linalg::veg::mem::AllocBlock::byte_cap
usize byte_cap
Definition
alloc.hpp:68
proxsuite::linalg::veg::mem::AllocBlock::data
void * data
Definition
alloc.hpp:67
proxsuite::linalg::veg::mem::Alloc
Definition
alloc.hpp:20
proxsuite::linalg::veg::mem::Cloner
Definition
alloc.hpp:23
proxsuite::linalg::veg::mem::Layout
Definition
alloc.hpp:71
proxsuite::linalg::veg::mem::Layout::byte_size
usize byte_size
Definition
alloc.hpp:72
proxsuite::linalg::veg::mem::Layout::align
usize align
Definition
alloc.hpp:73
proxsuite::linalg::veg::mem::RelocFn
Definition
alloc.hpp:76
proxsuite::linalg::veg::mem::RelocFn::fn
void *(* fn)(void *, void const *, usize)
Definition
alloc.hpp:77
proxsuite::linalg::veg::mem::RelocFn::operator()
VEG_INLINE void operator()(void *dst, void *src, usize n) const noexcept
Definition
alloc.hpp:79
proxsuite::linalg::veg::mem::RelocFn::is_trivial
VEG_INLINE auto is_trivial() const noexcept -> bool
Definition
alloc.hpp:85
typedefs.hpp
include
proxsuite
linalg
veg
type_traits
alloc.hpp
Generated by
1.17.0