Skip to content

Commit c9ec853

Browse files
committed
🐛 Don't assume std::array<>::iterator is a pointer
Problem: - Container classes define `iterator` as a pointer type but return `begin()` or `end()` of the underlying `std::array`, which is an iterator type, not necessarily a pointer. Solution: - Use `data()` instead of `begin()` where necessary.
1 parent fd1e82e commit c9ec853

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

include/stdx/cx_map.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,24 @@ template <typename Key, typename Value, std::size_t N> class cx_map {
4545
: storage{vs...}, current_size{sizeof...(Vs)} {}
4646

4747
[[nodiscard]] constexpr auto begin() LIFETIMEBOUND -> iterator {
48-
return std::begin(storage);
48+
return std::data(storage);
4949
}
5050
[[nodiscard]] constexpr auto begin() const LIFETIMEBOUND -> const_iterator {
51-
return std::begin(storage);
51+
return std::data(storage);
5252
}
5353
[[nodiscard]] constexpr auto
5454
cbegin() const LIFETIMEBOUND -> const_iterator {
55-
return std::cbegin(storage);
55+
return std::data(storage);
5656
}
5757

5858
[[nodiscard]] constexpr auto end() LIFETIMEBOUND -> iterator {
59-
return std::begin(storage) + current_size;
59+
return begin() + current_size;
6060
}
6161
[[nodiscard]] constexpr auto end() const LIFETIMEBOUND -> const_iterator {
62-
return std::begin(storage) + current_size;
62+
return begin() + current_size;
6363
}
6464
[[nodiscard]] constexpr auto cend() const LIFETIMEBOUND -> const_iterator {
65-
return std::cbegin(storage) + current_size;
65+
return cbegin() + current_size;
6666
}
6767

6868
[[nodiscard]] constexpr auto size() const -> std::size_t {

include/stdx/cx_set.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,24 @@ template <typename Key, std::size_t N> class cx_set {
3333
}
3434

3535
[[nodiscard]] constexpr auto begin() LIFETIMEBOUND -> iterator {
36-
return std::begin(storage);
36+
return std::data(storage);
3737
}
3838
[[nodiscard]] constexpr auto begin() const LIFETIMEBOUND -> const_iterator {
39-
return std::begin(storage);
39+
return std::data(storage);
4040
}
4141
[[nodiscard]] constexpr auto
4242
cbegin() const LIFETIMEBOUND -> const_iterator {
43-
return std::cbegin(storage);
43+
return std::data(storage);
4444
}
4545

4646
[[nodiscard]] constexpr auto end() LIFETIMEBOUND -> iterator {
47-
return std::begin(storage) + current_size;
47+
return begin() + current_size;
4848
}
4949
[[nodiscard]] constexpr auto end() const LIFETIMEBOUND -> const_iterator {
50-
return std::begin(storage) + current_size;
50+
return begin() + current_size;
5151
}
5252
[[nodiscard]] constexpr auto cend() const LIFETIMEBOUND -> const_iterator {
53-
return std::cbegin(storage) + current_size;
53+
return cbegin() + current_size;
5454
}
5555

5656
[[nodiscard]] constexpr auto size() const -> size_type {

include/stdx/cx_vector.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,24 +40,24 @@ template <typename T, std::size_t N> class cx_vector {
4040
}
4141

4242
[[nodiscard]] constexpr auto begin() LIFETIMEBOUND -> iterator {
43-
return std::begin(storage);
43+
return std::data(storage);
4444
}
4545
[[nodiscard]] constexpr auto begin() const LIFETIMEBOUND -> const_iterator {
46-
return std::begin(storage);
46+
return std::data(storage);
4747
}
4848
[[nodiscard]] constexpr auto
4949
cbegin() const LIFETIMEBOUND -> const_iterator {
50-
return std::cbegin(storage);
50+
return std::data(storage);
5151
}
5252

5353
[[nodiscard]] constexpr auto end() LIFETIMEBOUND -> iterator {
54-
return std::begin(storage) + current_size;
54+
return begin() + current_size;
5555
}
5656
[[nodiscard]] constexpr auto end() const LIFETIMEBOUND -> const_iterator {
57-
return std::begin(storage) + current_size;
57+
return begin() + current_size;
5858
}
5959
[[nodiscard]] constexpr auto cend() const LIFETIMEBOUND -> const_iterator {
60-
return std::cbegin(storage) + current_size;
60+
return cbegin() + current_size;
6161
}
6262

6363
[[nodiscard]] constexpr auto rbegin() LIFETIMEBOUND -> reverse_iterator {

0 commit comments

Comments
 (0)