Skip to content

Commit 336e2c4

Browse files
committed
StaticString::begin/end/available
1 parent 5121d03 commit 336e2c4

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

util/static_string.hh

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ struct StaticString {
7777
return _data;
7878
}
7979

80+
size_t available() const {
81+
return capacity - length();
82+
}
83+
8084
#ifdef CPPUTIL_STATIC_STRING_USE_STD_STRING
8185
operator std::string() const {
8286
return _data;
@@ -95,15 +99,20 @@ struct StaticString {
9599

96100
// volatile combinations:
97101
// clang-format off
98-
constexpr void copy(const char *s) volatile { const_cast<StaticString<CAPACITY>*>(this)->copy(s); }
102+
constexpr void copy(const char *s) volatile { const_cast<StaticString<CAPACITY>*>(this)->copy(s); }
103+
104+
template <size_t OTHER_CAP>
105+
constexpr void copy(StaticString<OTHER_CAP> const &other) { copy(other.data()); }
99106

100-
template <size_t OTHER_CAP>
101-
constexpr void copy(StaticString<OTHER_CAP> const &other) { copy(other.data()); }
107+
template <size_t OTHER_CAP>
108+
constexpr void copy(StaticString<OTHER_CAP> volatile const &other) volatile { copy(const_cast<StaticString<OTHER_CAP> const &>(other).data()); }
102109

103-
template <size_t OTHER_CAP>
104-
constexpr void copy(StaticString<OTHER_CAP> volatile const &other) volatile { copy(const_cast<StaticString<OTHER_CAP> const &>(other).data()); }
110+
template <size_t OTHER_CAP>
111+
constexpr void copy(StaticString<OTHER_CAP> const &other) volatile { copy(other.data()); }
105112

106-
template <size_t OTHER_CAP>
107-
constexpr void copy(StaticString<OTHER_CAP> const &other) volatile { copy(other.data()); }
113+
auto begin() { return _data; }
114+
auto end() { return _data + length(); }
115+
auto begin() const { return _data; }
116+
auto end() const { return _data + length(); }
108117
// clang-format on
109118
};

0 commit comments

Comments
 (0)