diff options
author | kshalnev <kshalnev@yandex-team.com> | 2024-02-14 13:31:06 +0300 |
---|---|---|
committer | kshalnev <kshalnev@yandex-team.com> | 2024-02-14 13:45:52 +0300 |
commit | f322cc04fdff5add8448b999da35b30e13c01554 (patch) | |
tree | 95e6a6d52c40e4e40ffe8004be5ab238cc3f403a /util | |
parent | f712f1ef01ce85418be783606914eb7ccfb51c08 (diff) | |
download | ydb-f322cc04fdff5add8448b999da35b30e13c01554.tar.gz |
Do not allow multiplication of TString and pointer
Diffstat (limited to 'util')
-rw-r--r-- | util/generic/string.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/util/generic/string.h b/util/generic/string.h index 3aadb2159b..b03b7f7625 100644 --- a/util/generic/string.h +++ b/util/generic/string.h @@ -7,6 +7,7 @@ #include <stdexcept> #include <string> #include <string_view> +#include <type_traits> #include <util/system/compiler.h> #include <util/system/yassert.h> @@ -814,8 +815,14 @@ public: template <class T> friend TBasicString operator*(const TBasicString& s, T count) { + static_assert(std::is_integral<T>::value, "Integral type required."); + TBasicString result; + if (count > 0) { + result.reserve(s.length() * count); + } + for (T i = 0; i < count; ++i) { result += s; } @@ -825,8 +832,14 @@ public: template <class T> TBasicString& operator*=(T count) { + static_assert(std::is_integral<T>::value, "Integral type required."); + TBasicString temp; + if (count > 0) { + temp.reserve(length() * count); + } + for (T i = 0; i < count; ++i) { temp += *this; } |