proxsuite
0.7.3
The Advanced Proximal Optimization Toolbox
Toggle main menu visibility
Loading...
Searching...
No Matches
slice.hpp
Go to the documentation of this file.
1
#ifndef VEG_SLICE_HPP_GKSTE2JDS
2
#define VEG_SLICE_HPP_GKSTE2JDS
3
4
#include "
proxsuite/linalg/veg/util/assert.hpp
"
5
#include "
proxsuite/linalg/veg/util/get.hpp
"
6
#include "
proxsuite/linalg/veg/internal/narrow.hpp
"
7
#include "
proxsuite/linalg/veg/tuple.hpp
"
8
#include "
proxsuite/linalg/veg/internal/prologue.hpp
"
9
#include <initializer_list>
10
11
namespace
proxsuite
{
12
namespace
linalg
{
13
namespace
veg
{
14
template
<
typename
T, usize N>
15
using
CArray
= T[N];
16
17
namespace
_detail
{
18
namespace
_slice
{
19
namespace
adl
{
20
struct
AdlBase
21
{};
22
}
// namespace adl
23
}
// namespace _slice
24
}
// namespace _detail
25
26
template
<
typename
T>
27
struct
Slice
: _detail::_slice::adl::AdlBase
28
{
29
private
:
30
T
const
* data =
nullptr
;
31
isize
size = 0;
32
33
public
:
34
VEG_INLINE
35
constexpr
Slice
() =
default
;
36
37
VEG_INLINE
38
constexpr
Slice
(Unsafe
/*tag*/
,
39
FromRawParts
/*tag*/
,
40
T
const
* data_,
41
isize
count)
VEG_NOEXCEPT
42
: data{ data_ }
43
, size{ count }
44
{
45
}
46
47
VEG_NODISCARD
48
VEG_INLINE
49
constexpr
auto
ptr
() const
VEG_NOEXCEPT
-> T const* {
return
data; }
50
VEG_NODISCARD
51
VEG_INLINE
52
constexpr
auto
len
() const
VEG_NOEXCEPT
->
isize
{
return
size; }
53
54
VEG_NODISCARD
55
VEG_INLINE
56
constexpr
auto
operator[]
(
isize
idx)
const
VEG_NOEXCEPT
->T
const
&
57
{
58
return
VEG_INTERNAL_ASSERT_PRECONDITION
(
usize
(idx) <
usize
(
len
())),
59
*(data + idx);
60
}
61
VEG_NODISCARD
62
VEG_INLINE
63
constexpr
auto
get_unchecked
(Unsafe
/*tag*/
,
isize
idx)
const
VEG_NOEXCEPT
64
->
Ref<T>
65
{
66
return
ref(*(data + idx));
67
}
68
69
VEG_NODISCARD
VEG_INLINE
constexpr
auto
split_at
(
isize
idx)
const
VEG_NOEXCEPT
70
->
Tuple<Slice<T>
,
Slice<T>
>
71
{
72
return
VEG_INTERNAL_ASSERT_PRECONDITION
(
usize
(idx) <=
usize
(
len
())),
73
Tuple<Slice<T>
,
Slice<T>
>{
74
tuplify,
75
Slice<T>
{
76
unsafe,
77
FromRawParts{},
78
data,
79
idx,
80
},
81
Slice<T>
{
82
unsafe,
83
FromRawParts{},
84
data + idx,
85
size - idx,
86
},
87
};
88
}
89
90
VEG_NODISCARD
VEG_INLINE
auto
as_bytes
() const
VEG_NOEXCEPT
91
->
Slice
<
unsigned
char
>
92
{
93
return
{
94
unsafe,
95
from_raw_parts,
96
reinterpret_cast<
unsigned
char
const*
>
(data),
97
isize
(
sizeof
(T)) * size,
98
};
99
}
100
};
101
102
template
<
typename
T>
103
struct
SliceMut
:
private
Slice
<T>
104
{
105
VEG_INLINE
106
constexpr
SliceMut
() =
default
;
107
108
VEG_INLINE
109
constexpr
SliceMut
(Unsafe
/*tag*/
,
110
FromRawParts
/*tag*/
,
111
T
const
* data_,
112
isize
count)
VEG_NOEXCEPT
113
:
Slice<T>
{
114
unsafe,
115
from_raw_parts,
116
data_,
117
count,
118
}
119
{
120
}
121
122
using
Slice
<T>
::ptr
;
123
using
Slice
<T>
::as_bytes
;
124
using
Slice
<T>
::split_at
;
125
using
Slice
<T>
::len
;
126
using
Slice
<T>
::get_unchecked
;
127
128
VEG_NODISCARD
VEG_INLINE
constexpr
auto
as_const
() const noexcept ->
Slice
<T>
129
{
130
return
*
this
;
131
}
132
133
VEG_NODISCARD
134
VEG_INLINE
135
VEG_CPP14
(
constexpr
) auto operator[](
isize
idx)
VEG_NOEXCEPT
->T&
136
{
137
return
const_cast<
T&
>
(
static_cast<
Slice<T>
const&
>
(*this)[idx]);
138
}
139
VEG_NODISCARD
140
VEG_INLINE
141
VEG_CPP14
(
constexpr
) auto ptr_mut()
VEG_NOEXCEPT
->T*
142
{
143
return
const_cast<
T*
>
(
ptr
());
144
}
145
VEG_NODISCARD
146
VEG_INLINE
147
VEG_CPP14
(
constexpr
)
148
auto
get_mut_unchecked
(Unsafe
/*tag*/
,
isize
idx)
VEG_NOEXCEPT
->
RefMut
<T>
149
{
150
return
mut(
const_cast<
T&
>
(*(this->data + idx)));
151
}
152
VEG_NODISCARD
VEG_INLINE
auto
as_mut_bytes
()
VEG_NOEXCEPT
153
->
SliceMut
<
unsigned
char
>
154
{
155
return
{
156
unsafe,
157
from_raw_parts,
158
reinterpret_cast<
unsigned
char
*
>
(ptr_mut()),
159
isize
(
sizeof
(T)) *
len
(),
160
};
161
}
162
163
VEG_NODISCARD
VEG_INLINE
VEG_CPP14
(
constexpr
) auto split_at_mut(
isize
idx)
164
VEG_NOEXCEPT
->
Tuple
<
SliceMut
<T>,
SliceMut
<T>>
165
{
166
return
VEG_INTERNAL_ASSERT_PRECONDITION
(
usize
(idx) <=
usize
(
len
())),
167
Tuple<SliceMut<T>
,
SliceMut<T>
>{
168
tuplify,
169
SliceMut<T>
{
170
unsafe,
171
from_raw_parts,
172
ptr_mut(),
173
idx,
174
},
175
SliceMut<T>
{
176
unsafe,
177
from_raw_parts,
178
ptr_mut() + idx,
179
len
() - idx,
180
},
181
};
182
}
183
};
184
185
namespace
array
{
186
template
<
typename
T, isize N>
187
struct
Array
188
{
189
static_assert
(N > 0,
"."
);
190
T
_
[
static_cast<
usize
>
(N)];
191
192
constexpr
auto
as_ref
() const ->
Slice
<T>
193
{
194
return
{
195
unsafe,
196
from_raw_parts,
197
static_cast<
T const*
>
(
_
),
198
N,
199
};
200
}
201
VEG_CPP14
(
constexpr
) auto as_mut() ->
SliceMut
<T>
202
{
203
return
{
204
unsafe,
205
from_raw_parts,
206
static_cast<
T*
>
(
_
),
207
N,
208
};
209
}
210
};
211
}
// namespace array
212
using
array::Array;
213
214
namespace
nb {
215
struct
init_list
216
{
217
template
<
typename
T>
218
VEG_CPP14
(
constexpr
)
219
auto operator()(
std
::initializer_list<T>
init_list
) const noexcept ->
Slice
<T>
220
{
221
return
{
222
unsafe,
223
from_raw_parts,
224
init_list
.begin(),
225
isize
(
init_list
.size()),
226
};
227
}
228
};
229
}
// namespace nb
230
VEG_NIEBLOID
(init_list);
231
232
template
<
typename
T>
233
struct
cpo::is_trivially_constructible
<
Slice
<T>> :
meta::bool_constant
<true>
234
{};
235
}
// namespace veg
236
}
// namespace linalg
237
}
// namespace proxsuite
238
239
#include "
proxsuite/linalg/veg/internal/epilogue.hpp
"
240
#endif
/* end of include guard VEG_SLICE_HPP_GKSTE2JDS */
assert.hpp
epilogue.hpp
get.hpp
VEG_NIEBLOID
#define VEG_NIEBLOID(Name)
Definition
macros.hpp:545
VEG_INLINE
#define VEG_INLINE
Definition
macros.hpp:118
proxsuite::linalg::veg::_detail::_slice::adl
Definition
slice.hpp:19
proxsuite::linalg::veg::_detail::_slice
Definition
slice.hpp:18
proxsuite::linalg::veg::_detail
Definition
collection_algo.hpp:11
proxsuite::linalg::veg::array
Definition
slice.hpp:185
proxsuite::linalg::veg::meta::bool_constant
constant< bool, B > bool_constant
Definition
macros.hpp:897
proxsuite::linalg::veg
Definition
collection_algo.hpp:10
proxsuite::linalg::veg::usize
decltype(sizeof(0)) usize
Definition
macros.hpp:699
proxsuite::linalg::veg::CArray
T[N] CArray
Definition
slice.hpp:15
proxsuite::linalg::veg::isize
_detail::_meta::make_signed< usize >::Type isize
Definition
typedefs.hpp:43
proxsuite::linalg
Definition
core.hpp:85
proxsuite
Definition
common.hpp:14
std
STL namespace.
narrow.hpp
prologue.hpp
VEG_INTERNAL_ASSERT_PRECONDITION
#define VEG_INTERNAL_ASSERT_PRECONDITION
Definition
prologue.hpp:100
VEG_NODISCARD
#define VEG_NODISCARD
Definition
prologue.hpp:97
VEG_NOEXCEPT
#define VEG_NOEXCEPT
Definition
prologue.hpp:30
VEG_CPP14
#define VEG_CPP14(...)
Definition
prologue.hpp:71
proxsuite::linalg::sparse::SliceMut::SliceMut
VEG_INLINE constexpr SliceMut()=default
proxsuite::linalg::sparse::Slice::Slice
VEG_INLINE constexpr Slice()=default
proxsuite::linalg::veg::RefMut
Definition
ref.hpp:68
proxsuite::linalg::veg::Ref
Definition
ref.hpp:30
proxsuite::linalg::veg::SliceMut
Definition
slice.hpp:104
proxsuite::linalg::veg::SliceMut::as_mut_bytes
VEG_NODISCARD VEG_INLINE auto as_mut_bytes() VEG_NOEXCEPT -> SliceMut< unsigned char >
Definition
slice.hpp:152
proxsuite::linalg::veg::SliceMut::get_mut_unchecked
VEG_NODISCARD VEG_INLINE auto get_mut_unchecked(Unsafe, isize idx) VEG_NOEXCEPT -> RefMut< T >
Definition
slice.hpp:148
proxsuite::linalg::veg::SliceMut::SliceMut
VEG_INLINE constexpr SliceMut()=default
proxsuite::linalg::veg::SliceMut::VEG_CPP14
VEG_NODISCARD VEG_INLINE VEG_CPP14(constexpr) auto ptr_mut() VEG_NOEXCEPT -> T *
Definition
slice.hpp:141
proxsuite::linalg::veg::SliceMut::VEG_CPP14
VEG_NODISCARD VEG_INLINE VEG_CPP14(constexpr) auto split_at_mut(isize idx) VEG_NOEXCEPT -> Tuple< SliceMut< T >, SliceMut< T > >
Definition
slice.hpp:163
proxsuite::linalg::veg::SliceMut::as_const
VEG_NODISCARD VEG_INLINE constexpr auto as_const() const noexcept -> Slice< T >
Definition
slice.hpp:128
proxsuite::linalg::veg::SliceMut::VEG_CPP14
VEG_NODISCARD VEG_INLINE VEG_CPP14(constexpr) auto operator[](isize idx) VEG_NOEXCEPT -> T &
Definition
slice.hpp:135
proxsuite::linalg::veg::SliceMut::SliceMut
VEG_INLINE constexpr SliceMut(Unsafe, FromRawParts, T const *data_, isize count) VEG_NOEXCEPT
Definition
slice.hpp:109
proxsuite::linalg::veg::Slice
Definition
slice.hpp:28
proxsuite::linalg::veg::Slice::Slice
VEG_INLINE constexpr Slice(Unsafe, FromRawParts, T const *data_, isize count) VEG_NOEXCEPT
Definition
slice.hpp:38
proxsuite::linalg::veg::Slice::len
VEG_NODISCARD VEG_INLINE constexpr auto len() const VEG_NOEXCEPT -> isize
Definition
slice.hpp:52
proxsuite::linalg::veg::Slice::ptr
VEG_NODISCARD VEG_INLINE constexpr auto ptr() const VEG_NOEXCEPT -> T const *
Definition
slice.hpp:49
proxsuite::linalg::veg::Slice::get_unchecked
VEG_NODISCARD VEG_INLINE constexpr auto get_unchecked(Unsafe, isize idx) const VEG_NOEXCEPT -> Ref< T >
Definition
slice.hpp:63
proxsuite::linalg::veg::Slice::Slice
VEG_INLINE constexpr Slice()=default
proxsuite::linalg::veg::Slice::operator[]
VEG_NODISCARD VEG_INLINE constexpr auto operator[](isize idx) const VEG_NOEXCEPT -> T const &
Definition
slice.hpp:56
proxsuite::linalg::veg::Slice::split_at
VEG_NODISCARD VEG_INLINE constexpr auto split_at(isize idx) const VEG_NOEXCEPT -> Tuple< Slice< T >, Slice< T > >
Definition
slice.hpp:69
proxsuite::linalg::veg::Slice::as_bytes
VEG_NODISCARD VEG_INLINE auto as_bytes() const VEG_NOEXCEPT -> Slice< unsigned char >
Definition
slice.hpp:90
proxsuite::linalg::veg::Tuple
Definition
tuple.hpp:508
proxsuite::linalg::veg::_detail::_slice::adl::AdlBase
Definition
slice.hpp:21
proxsuite::linalg::veg::array::Array
Definition
slice.hpp:188
proxsuite::linalg::veg::array::Array::_
T _[static_cast< usize >(N)]
Definition
slice.hpp:190
proxsuite::linalg::veg::array::Array::VEG_CPP14
VEG_CPP14(constexpr) auto as_mut() -> SliceMut< T >
Definition
slice.hpp:201
proxsuite::linalg::veg::array::Array::as_ref
constexpr auto as_ref() const -> Slice< T >
Definition
slice.hpp:192
proxsuite::linalg::veg::cpo::is_trivially_constructible
Definition
constructible.hpp:143
proxsuite::linalg::veg::nb::init_list
Definition
slice.hpp:216
tuple.hpp
include
proxsuite
linalg
veg
slice.hpp
Generated by
1.17.0