|
1 | 1 | #pragma once |
2 | 2 |
|
3 | 3 | #include "./types.hpp" |
| 4 | +#include "./utils.hpp" |
4 | 5 |
|
5 | 6 | #include <algorithm> |
6 | 7 | #include <array> |
@@ -29,19 +30,29 @@ struct StaticString { |
29 | 30 | return size(); |
30 | 31 | } |
31 | 32 |
|
32 | | - [[nodiscard]] constexpr char* begin() { |
| 33 | + // iterator trait |
| 34 | + using iterator = char * ; //NOLINT(readability-identifier-naming) |
| 35 | + using const_iterator = const char*; //NOLINT(readability-identifier-naming) |
| 36 | + using difference_type = std::ptrdiff_t; //NOLINT(readability-identifier-naming) |
| 37 | + using value_type = char; //NOLINT(readability-identifier-naming) |
| 38 | + using pointer = char * ; //NOLINT(readability-identifier-naming) |
| 39 | + using reference = char&; //NOLINT(readability-identifier-naming) |
| 40 | + using iterator_category = std::bidirectional_iterator_tag; //NOLINT(readability-identifier-naming) |
| 41 | + |
| 42 | + |
| 43 | + [[nodiscard]] constexpr iterator begin() { |
33 | 44 | return m_data.data(); |
34 | 45 | } |
35 | 46 |
|
36 | | - [[nodiscard]] constexpr char* end() { |
37 | | - return begin() + length(); |
| 47 | + [[nodiscard]] constexpr const_iterator begin() const { |
| 48 | + return m_data.data(); |
38 | 49 | } |
39 | 50 |
|
40 | | - [[nodiscard]] constexpr const char* begin() const { |
41 | | - return m_data.data(); |
| 51 | + [[nodiscard]] constexpr iterator end() { |
| 52 | + return begin() + length(); |
42 | 53 | } |
43 | 54 |
|
44 | | - [[nodiscard]] constexpr const char* end() const { |
| 55 | + [[nodiscard]] constexpr const_iterator end() const { |
45 | 56 | return m_data.data() + size(); |
46 | 57 | } |
47 | 58 |
|
@@ -132,3 +143,5 @@ struct StaticString { |
132 | 143 | template<usize other_data_size> |
133 | 144 | friend struct StaticString; |
134 | 145 | }; |
| 146 | + |
| 147 | +STATIC_ASSERT_WITH_MESSAGE(utils::IsIterator<StaticString<3>>::value, "StaticString<T> has to be an iterator"); |
0 commit comments