Skip to content

Commit e8fed85

Browse files
committed
Add lifetime annotations to features of utility/*
1 parent 701a916 commit e8fed85

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

include/cpp-sort/utility/adapter_storage.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
////////////////////////////////////////////////////////////
1111
#include <type_traits>
1212
#include <utility>
13+
#include "../detail/config.h"
1314

1415
namespace cppsort::utility
1516
{
@@ -87,24 +88,28 @@ namespace cppsort::utility
8788
}
8889

8990
constexpr auto get() & noexcept
91+
CPPSORT_LIFETIME_BOUND
9092
-> Sorter&
9193
{
9294
return static_cast<Sorter&>(sorter);
9395
}
9496

9597
constexpr auto get() const& noexcept
98+
CPPSORT_LIFETIME_BOUND
9699
-> const Sorter&
97100
{
98101
return static_cast<const Sorter&>(sorter);
99102
}
100103

101104
constexpr auto get() && noexcept
105+
CPPSORT_LIFETIME_BOUND
102106
-> Sorter&&
103107
{
104108
return static_cast<Sorter&&>(sorter);
105109
}
106110

107111
constexpr auto get() const&& noexcept
112+
CPPSORT_LIFETIME_BOUND
108113
-> const Sorter&&
109114
{
110115
return static_cast<const Sorter&&>(sorter);

include/cpp-sort/utility/buffer.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <array>
1212
#include <cstddef>
1313
#include <memory>
14+
#include "../detail/config.h"
1415

1516
namespace cppsort::utility
1617
{
@@ -39,48 +40,56 @@ namespace cppsort::utility
3940
}
4041

4142
constexpr auto operator[](std::size_t pos)
43+
CPPSORT_LIFETIME_BOUND
4244
-> decltype(_memory[pos])
4345
{
4446
return _memory[pos];
4547
}
4648

4749
constexpr auto operator[](std::size_t pos) const
50+
CPPSORT_LIFETIME_BOUND
4851
-> decltype(_memory[pos])
4952
{
5053
return _memory[pos];
5154
}
5255

5356
constexpr auto begin()
57+
CPPSORT_LIFETIME_BOUND
5458
-> decltype(_memory.data())
5559
{
5660
return _memory.data();
5761
}
5862

5963
constexpr auto begin() const
64+
CPPSORT_LIFETIME_BOUND
6065
-> decltype(_memory.data())
6166
{
6267
return _memory.data();
6368
}
6469

6570
constexpr auto cbegin() const
71+
CPPSORT_LIFETIME_BOUND
6672
-> decltype(_memory.data())
6773
{
6874
return _memory.data();
6975
}
7076

7177
constexpr auto end()
78+
CPPSORT_LIFETIME_BOUND
7279
-> decltype(_memory.data() + _memory.size())
7380
{
7481
return _memory.data() + _memory.size();
7582
}
7683

7784
constexpr auto end() const
85+
CPPSORT_LIFETIME_BOUND
7886
-> decltype(_memory.data() + _memory.size())
7987
{
8088
return _memory.data() + _memory.size();
8189
}
8290

8391
constexpr auto cend() const
92+
CPPSORT_LIFETIME_BOUND
8493
-> decltype(_memory.data() + _memory.size())
8594
{
8695
return _memory.data() + _memory.size();
@@ -193,48 +202,56 @@ namespace cppsort::utility
193202
}
194203

195204
auto operator[](std::size_t pos)
205+
CPPSORT_LIFETIME_BOUND
196206
-> decltype(_memory[pos])
197207
{
198208
return _memory[pos];
199209
}
200210

201211
auto operator[](std::size_t pos) const
212+
CPPSORT_LIFETIME_BOUND
202213
-> decltype(_memory[pos])
203214
{
204215
return _memory[pos];
205216
}
206217

207218
auto begin()
219+
CPPSORT_LIFETIME_BOUND
208220
-> decltype(_memory.get())
209221
{
210222
return _memory.get();
211223
}
212224

213225
auto begin() const
226+
CPPSORT_LIFETIME_BOUND
214227
-> decltype(_memory.get())
215228
{
216229
return _memory.get();
217230
}
218231

219232
auto cbegin() const
233+
CPPSORT_LIFETIME_BOUND
220234
-> decltype(_memory.get())
221235
{
222236
return _memory.get();
223237
}
224238

225239
auto end()
240+
CPPSORT_LIFETIME_BOUND
226241
-> decltype(_memory.get() + size())
227242
{
228243
return _memory.get() + size();
229244
}
230245

231246
auto end() const
247+
CPPSORT_LIFETIME_BOUND
232248
-> decltype(_memory.get() + size())
233249
{
234250
return _memory.get() + size();
235251
}
236252

237253
auto cend() const
254+
CPPSORT_LIFETIME_BOUND
238255
-> decltype(_memory.get() + size())
239256
{
240257
return _memory.get() + size();

include/cpp-sort/utility/metrics_tools.h

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <tuple>
1313
#include <type_traits>
1414
#include <utility>
15+
#include "../detail/config.h"
1516
#include "../detail/type_traits.h"
1617

1718
namespace cppsort::utility
@@ -70,6 +71,7 @@ namespace cppsort::utility
7071

7172
constexpr auto operator=(const T& other)
7273
noexcept(std::is_nothrow_copy_assignable_v<T>)
74+
CPPSORT_LIFETIME_BOUND
7375
-> metric&
7476
{
7577
_value = other;
@@ -78,6 +80,7 @@ namespace cppsort::utility
7880

7981
constexpr auto operator=(T&& other)
8082
noexcept(std::is_nothrow_move_assignable_v<T>)
83+
CPPSORT_LIFETIME_BOUND
8184
-> metric&
8285
{
8386
_value = std::move(other);
@@ -87,6 +90,7 @@ namespace cppsort::utility
8790
template<typename U>
8891
constexpr auto operator=(const metric<U, Tag>& other)
8992
noexcept(std::is_nothrow_assignable_v<T&, const U&>)
93+
CPPSORT_LIFETIME_BOUND
9094
-> metric&
9195
{
9296
_value = other._value;
@@ -96,6 +100,7 @@ namespace cppsort::utility
96100
template<typename U>
97101
constexpr auto operator=(metric<U, Tag>&& other)
98102
noexcept(std::is_nothrow_assignable_v<T&, U>)
103+
CPPSORT_LIFETIME_BOUND
99104
-> metric&
100105
{
101106
_value = std::move(other._value);
@@ -271,28 +276,28 @@ namespace cppsort::utility
271276
// Index-based get()
272277

273278
template<std::size_t Idx>
274-
friend constexpr auto get(metrics& mm)
279+
friend constexpr auto get(metrics& mm CPPSORT_LIFETIME_BOUND)
275280
-> std::tuple_element_t<Idx, std::tuple<metric<TT, Tags>...>>&
276281
{
277282
return std::get<Idx>(mm.metrics_);
278283
}
279284

280285
template<std::size_t Idx>
281-
friend constexpr auto get(const metrics& mm)
286+
friend constexpr auto get(const metrics& mm CPPSORT_LIFETIME_BOUND)
282287
-> const std::tuple_element_t<Idx, std::tuple<metric<TT, Tags>...>>&
283288
{
284289
return std::get<Idx>(mm.metrics_);
285290
}
286291

287292
template<std::size_t Idx>
288-
friend constexpr auto get(metrics&& mm)
293+
friend constexpr auto get(metrics&& mm CPPSORT_LIFETIME_BOUND)
289294
-> std::tuple_element_t<Idx, std::tuple<metric<TT, Tags>...>>&&
290295
{
291296
return std::get<Idx>(std::move(mm).metrics_);
292297
}
293298

294299
template<std::size_t Idx>
295-
friend constexpr auto get(const metrics&& mm)
300+
friend constexpr auto get(const metrics&& mm CPPSORT_LIFETIME_BOUND)
296301
-> const std::tuple_element_t<Idx, std::tuple<metric<TT, Tags>...>>&&
297302
{
298303
return std::get<Idx>(std::move(mm).metrics_);
@@ -302,28 +307,28 @@ namespace cppsort::utility
302307
// Tag-based get()
303308

304309
template<typename Tag, std::size_t Idx=cppsort::detail::index_of<Tag, Tags...>>
305-
friend constexpr auto get(metrics& mm)
310+
friend constexpr auto get(metrics& mm CPPSORT_LIFETIME_BOUND)
306311
-> std::tuple_element_t<Idx, std::tuple<metric<TT, Tags>...>>&
307312
{
308313
return std::get<Idx>(mm.metrics_);
309314
}
310315

311316
template<typename Tag, std::size_t Idx=cppsort::detail::index_of<Tag, Tags...>>
312-
friend constexpr auto get(const metrics& mm)
317+
friend constexpr auto get(const metrics& mm CPPSORT_LIFETIME_BOUND)
313318
-> const std::tuple_element_t<Idx, std::tuple<metric<TT, Tags>...>>&
314319
{
315320
return std::get<Idx>(mm.metrics_);
316321
}
317322

318323
template<typename Tag, std::size_t Idx=cppsort::detail::index_of<Tag, Tags...>>
319-
friend constexpr auto get(metrics&& mm)
324+
friend constexpr auto get(metrics&& mm CPPSORT_LIFETIME_BOUND)
320325
-> std::tuple_element_t<Idx, std::tuple<metric<TT, Tags>...>>&&
321326
{
322327
return std::get<Idx>(std::move(mm).metrics_);
323328
}
324329

325330
template<typename Tag, std::size_t Idx=cppsort::detail::index_of<Tag, Tags...>>
326-
friend constexpr auto get(const metrics&& mm)
331+
friend constexpr auto get(const metrics&& mm CPPSORT_LIFETIME_BOUND)
327332
-> const std::tuple_element_t<Idx, std::tuple<metric<TT, Tags>...>>&&
328333
{
329334
return std::get<Idx>(std::move(mm).metrics_);

0 commit comments

Comments
 (0)