Skip to content

Commit 701a916

Browse files
committed
Mark internal container functions with lifetimebound attribute
1 parent ebd2b07 commit 701a916

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

include/cpp-sort/detail/config.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,19 @@
142142
# endif
143143
#endif
144144

145+
////////////////////////////////////////////////////////////
146+
// CPPSORT_LIFETIME_BOUND
147+
148+
#ifdef __has_cpp_attribute
149+
# if __has_cpp_attribute(clang::lifetimebound)
150+
# define CPPSORT_LIFETIME_BOUND [[clang::lifetimebound]]
151+
# elif __has_cpp_attribute(msvc::lifetimebound)
152+
# define CPPSORT_LIFETIME_BOUND [[msvc::lifetimebound]]
153+
# else
154+
# define CPPSORT_LIFETIME_BOUND
155+
# endif
156+
#else
157+
# define CPPSORT_LIFETIME_BOUND
158+
#endif
159+
145160
#endif // CPPSORT_DETAIL_CONFIG_H_

include/cpp-sort/detail/fixed_size_list.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ namespace cppsort::detail
175175

176176
[[nodiscard]]
177177
auto next_free_node() noexcept
178+
CPPSORT_LIFETIME_BOUND
178179
-> node_type*
179180
{
180181
// Retrieve next free node
@@ -487,13 +488,15 @@ namespace cppsort::detail
487488

488489
[[nodiscard]]
489490
auto front() noexcept
491+
CPPSORT_LIFETIME_BOUND
490492
-> reference
491493
{
492494
return static_cast<node_type*>(sentinel_node_.next)->value;
493495
}
494496

495497
[[nodiscard]]
496498
auto back() noexcept
499+
CPPSORT_LIFETIME_BOUND
497500
-> reference
498501
{
499502
return static_cast<node_type*>(sentinel_node_.prev)->value;
@@ -511,13 +514,15 @@ namespace cppsort::detail
511514

512515
[[nodiscard]]
513516
auto begin() noexcept
517+
CPPSORT_LIFETIME_BOUND
514518
-> iterator
515519
{
516520
return iterator(sentinel_node_.next);
517521
}
518522

519523
[[nodiscard]]
520524
auto end() noexcept
525+
CPPSORT_LIFETIME_BOUND
521526
-> iterator
522527
{
523528
return iterator(&sentinel_node_);
@@ -537,12 +542,14 @@ namespace cppsort::detail
537542
// Modifiers
538543

539544
auto insert(iterator pos, const value_type& value)
545+
CPPSORT_LIFETIME_BOUND
540546
-> iterator
541547
{
542548
return iterator(insert_node_(pos.base(), value));
543549
}
544550

545551
auto insert(iterator pos, value_type&& value)
552+
CPPSORT_LIFETIME_BOUND
546553
-> iterator
547554
{
548555
return iterator(insert_node_(pos.base(), std::move(value)));
@@ -781,6 +788,7 @@ namespace cppsort::detail
781788
// Helper functions
782789

783790
auto insert_node_(list_node_base* pos, const value_type& value)
791+
CPPSORT_LIFETIME_BOUND
784792
-> node_type*
785793
{
786794
node_type* new_node = node_pool_->next_free_node();
@@ -790,6 +798,7 @@ namespace cppsort::detail
790798
}
791799

792800
auto insert_node_(list_node_base* pos, value_type&& value)
801+
CPPSORT_LIFETIME_BOUND
793802
-> node_type*
794803
{
795804
node_type* new_node = node_pool_->next_free_node();
@@ -800,6 +809,7 @@ namespace cppsort::detail
800809

801810
template<typename Callable>
802811
auto insert_node_(list_node_base* pos, Callable setter)
812+
CPPSORT_LIFETIME_BOUND
803813
-> node_type*
804814
{
805815
node_type* new_node = node_pool_->next_free_node();

include/cpp-sort/detail/immovable_vector.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,20 +71,23 @@ namespace cppsort::detail
7171
// Element access
7272

7373
auto operator[](std::ptrdiff_t pos) noexcept
74+
CPPSORT_LIFETIME_BOUND
7475
-> T&
7576
{
7677
CPPSORT_ASSERT(pos <= end_ - memory_);
7778
return memory_[pos];
7879
}
7980

8081
auto front() noexcept
82+
CPPSORT_LIFETIME_BOUND
8183
-> T&
8284
{
8385
CPPSORT_ASSERT(memory_ != end_);
8486
return *memory_;
8587
}
8688

8789
auto back() noexcept
90+
CPPSORT_LIFETIME_BOUND
8891
-> T&
8992
{
9093
CPPSORT_ASSERT(end_ - memory_ > 0);
@@ -95,12 +98,14 @@ namespace cppsort::detail
9598
// Iterators
9699

97100
auto begin() noexcept
101+
CPPSORT_LIFETIME_BOUND
98102
-> T*
99103
{
100104
return memory_;
101105
}
102106

103107
auto end() noexcept
108+
CPPSORT_LIFETIME_BOUND
104109
-> T*
105110
{
106111
return end_;
@@ -121,6 +126,7 @@ namespace cppsort::detail
121126

122127
template<typename... Args>
123128
auto emplace_back(Args&&... args)
129+
CPPSORT_LIFETIME_BOUND
124130
-> T*
125131
{
126132
CPPSORT_ASSERT(end_ - memory_ < capacity_);

0 commit comments

Comments
 (0)