Skip to content

Commit db179d7

Browse files
author
Swagtoy
committed
Take in suggestions, remove template garbage (let's wait til C++20 anyway)
1 parent 248058e commit db179d7

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

irr/include/irrString.h

+16-12
Original file line numberDiff line numberDiff line change
@@ -166,26 +166,30 @@ class string
166166
}
167167

168168
//! Assignment operator for strings, ASCII and Unicode
169-
template <class B, std::enable_if_t<std::is_array_v<B[]>, bool> = true>
169+
template <class B>
170170
string<T> &operator=(const B * c)
171171
{
172172
if (!c) {
173173
clear();
174174
return *this;
175175
}
176176

177-
_IRR_DEBUG_BREAK_IF(
178-
reinterpret_cast<uintptr_t>(c) >= (uintptr_t)(str.data()) &&
179-
reinterpret_cast<uintptr_t>(c) < (uintptr_t)(str.data()) + str.size());
180-
181-
u32 len = calclen(c);
182-
// In case `c` is a pointer to our own buffer, we may not resize first
183-
// or it can become invalid.
184-
if (len > str.size()) str.resize(len);
185-
for (u32 l = 0; l < len; ++l)
186-
str[l] = static_cast<T>(c[l]);
187-
if (len < str.size()) str.resize(len);
177+
if constexpr (sizeof(T) != sizeof(B)) {
178+
_IRR_DEBUG_BREAK_IF(
179+
(uintptr_t)c >= (uintptr_t)(str.data()) &&
180+
(uintptr_t)c < (uintptr_t)(str.data() + str.size()));
181+
}
188182

183+
u32 len = calclen(c);
184+
// In case `c` is a pointer to our own buffer, we may not resize first
185+
// or it can become invalid.
186+
if (len > str.size())
187+
str.resize(len);
188+
for (u32 l = 0; l < len; ++l)
189+
str[l] = static_cast<T>(c[l]);
190+
if (len < str.size())
191+
str.resize(len);
192+
189193
return *this;
190194
}
191195

0 commit comments

Comments
 (0)