Skip to content

Commit 3d33dfc

Browse files
committed
✨ Add ct_capacity
1 parent 7631cf8 commit 3d33dfc

17 files changed

Lines changed: 223 additions & 5 deletions

docs/index.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ include::cx_vector.adoc[]
2222
include::for_each_n_args.adoc[]
2323
include::function_traits.adoc[]
2424
include::functional.adoc[]
25+
include::intrusive_forward_list.adoc[]
2526
include::intrusive_list.adoc[]
27+
include::iterator.adoc[]
2628
include::memory.adoc[]
2729
include::optional.adoc[]
2830
include::panic.adoc[]

docs/intro.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ The following headers are available:
4848
* https://github.com/intel/cpp-std-extensions/blob/main/include/stdx/for_each_n_args.hpp[`for_each_n_args.hpp`]
4949
* https://github.com/intel/cpp-std-extensions/blob/main/include/stdx/function_traits.hpp[`function_traits.hpp`]
5050
* https://github.com/intel/cpp-std-extensions/blob/main/include/stdx/functional.hpp[`functional.hpp`]
51+
* https://github.com/intel/cpp-std-extensions/blob/main/include/stdx/intrusive_forward_list.hpp[`intrusive_forward_list.hpp`]
5152
* https://github.com/intel/cpp-std-extensions/blob/main/include/stdx/intrusive_list.hpp[`intrusive_list.hpp`]
53+
* https://github.com/intel/cpp-std-extensions/blob/main/include/stdx/iterator.hpp[`iterator.hpp`]
5254
* https://github.com/intel/cpp-std-extensions/blob/main/include/stdx/memory.hpp[`memory.hpp`]
5355
* https://github.com/intel/cpp-std-extensions/blob/main/include/stdx/optional.hpp[`optional.hpp`]
5456
* https://github.com/intel/cpp-std-extensions/blob/main/include/stdx/panic.hpp[`panic.hpp`]

docs/intrusive_forward_list.adoc

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
2+
== `intrusive_forward_list.hpp`
3+
4+
`intrusive_forward_list` is a singly-linked list designed for use at compile-time or
5+
with static objects. It supports pushing and popping at the front or back, and
6+
removal from the middle.
7+
8+
[source,cpp]
9+
----
10+
// A node in an intrusive_list must have a next pointer
11+
struct node {
12+
node *next{};
13+
};
14+
15+
stdx::intrusive_forward_list<node> l;
16+
17+
node n1{};
18+
l.push_front(&n1);
19+
20+
node n2{};
21+
l.push_back(&n2);
22+
23+
node n3{};
24+
l.push_back(&n3);
25+
26+
node* nf = l.pop_front();
27+
28+
l.clear();
29+
bool b = l.empty();
30+
----

docs/intrusive_list.adoc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ node n3{};
2525
l.push_back(&n3);
2626
2727
l.remove(&n2); // removal from the middle is constant-time
28-
l.pop_front();
29-
l.pop_back();
28+
node* nf = l.pop_front();
29+
node* nb = l.pop_back();
30+
31+
l.clear();
32+
bool b = l.empty();
3033
----

docs/iterator.adoc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
== `iterator.hpp`
3+
4+
https://github.com/intel/cpp-std-extensions/blob/main/include/stdx/iterator.hpp[`iterator.hpp`]
5+
contains `ct_capacity`, a `constexpr` function that returns the capacity of a
6+
container which is known at compile-time.
7+
8+
[source,cpp]
9+
----
10+
auto const a = std::array{1, 2, 3, 4};
11+
constexpr auto c = stdx::ct_capacity(a); // std::size_t{4}
12+
----
13+
14+
`ct_capacity` can be called with:
15+
16+
* `std::array`
17+
* `std::span` (unless it has `std::dynamic_extent`)
18+
* `stdx::span` (unless it has `stdx::dynamic_extent`)
19+
* `stdx::cx_map`
20+
* `stdx::cx_multimap`
21+
* `stdx::cx_queue`
22+
* `stdx::cx_set`
23+
* `stdx::cx_vector`
24+
25+
`ct_capacity_v` is a corresponding variable template of type `std::size_t`.

include/stdx/cx_map.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include <stdx/concepts.hpp>
4+
#include <stdx/iterator.hpp>
45
#include <stdx/utility.hpp>
56

67
#include <array>
@@ -126,5 +127,8 @@ template <typename Key, typename Value, std::size_t N> class cx_map {
126127
return 0u;
127128
}
128129
};
130+
131+
template <typename K, typename V, std::size_t N>
132+
constexpr auto ct_capacity_v<cx_map<K, V, N>> = N;
129133
} // namespace v1
130134
} // namespace stdx

include/stdx/cx_multimap.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <stdx/cx_map.hpp>
44
#include <stdx/cx_set.hpp>
5+
#include <stdx/iterator.hpp>
56

67
#include <cstddef>
78
#include <iterator>
@@ -99,5 +100,8 @@ class cx_multimap {
99100

100101
constexpr auto clear() -> void { storage.clear(); }
101102
};
103+
104+
template <typename K, typename V, std::size_t N, std::size_t M>
105+
constexpr auto ct_capacity_v<cx_multimap<K, V, N, M>> = N;
102106
} // namespace v1
103107
} // namespace stdx

include/stdx/cx_queue.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#pragma once
22

3+
#include <stdx/iterator.hpp>
34
#include <stdx/panic.hpp>
45

56
#include <array>
@@ -104,5 +105,8 @@ class cx_queue {
104105
return entry;
105106
}
106107
};
108+
109+
template <typename T, std::size_t N, typename OP>
110+
constexpr auto ct_capacity_v<cx_queue<T, N, OP>> = N;
107111
} // namespace v1
108112
} // namespace stdx

include/stdx/cx_set.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <stdx/concepts.hpp>
44
#include <stdx/cx_map.hpp>
5+
#include <stdx/iterator.hpp>
56

67
#include <cstddef>
78

@@ -107,5 +108,8 @@ template <typename Key, std::size_t N> class cx_set {
107108

108109
template <typename T, typename... Ts>
109110
cx_set(T, Ts...) -> cx_set<T, 1 + sizeof...(Ts)>;
111+
112+
template <typename T, std::size_t N>
113+
constexpr auto ct_capacity_v<cx_set<T, N>> = N;
110114
} // namespace v1
111115
} // namespace stdx

include/stdx/cx_vector.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include <stdx/concepts.hpp>
4+
#include <stdx/iterator.hpp>
45

56
#include <array>
67
#include <cstddef>
@@ -167,5 +168,8 @@ template <std::size_t I, typename T, std::size_t N>
167168
auto get(cx_vector<T, N> const &v) -> decltype(auto) {
168169
return v.template get<I>();
169170
}
171+
172+
template <typename T, std::size_t N>
173+
constexpr auto ct_capacity_v<cx_vector<T, N>> = N;
170174
} // namespace v1
171175
} // namespace stdx

0 commit comments

Comments
 (0)