diff options
author | eeight <eeight@yandex-team.ru> | 2022-02-10 16:46:18 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:18 +0300 |
commit | 475c0a46f28166e83fd263badc7546377cddcabe (patch) | |
tree | 39c5a49b8aaad78fe390b6f1f2886bdbda40f3e7 /util/generic | |
parent | a6e0145a095c7bb3770d6e07aee301de5c73f96e (diff) | |
download | ydb-475c0a46f28166e83fd263badc7546377cddcabe.tar.gz |
Restoring authorship annotation for <eeight@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util/generic')
-rw-r--r-- | util/generic/bitops.h | 16 | ||||
-rw-r--r-- | util/generic/buffer.cpp | 6 | ||||
-rw-r--r-- | util/generic/cast.h | 34 | ||||
-rw-r--r-- | util/generic/cast_ut.cpp | 52 | ||||
-rw-r--r-- | util/generic/guid.cpp | 2 | ||||
-rw-r--r-- | util/generic/hash.h | 44 | ||||
-rw-r--r-- | util/generic/hash.pxd | 2 | ||||
-rw-r--r-- | util/generic/hash_set.h | 18 | ||||
-rw-r--r-- | util/generic/hash_ut.cpp | 42 | ||||
-rw-r--r-- | util/generic/hash_ut.pyx | 4 | ||||
-rw-r--r-- | util/generic/map.h | 12 | ||||
-rw-r--r-- | util/generic/map_ut.cpp | 6 | ||||
-rw-r--r-- | util/generic/overloaded.h | 8 | ||||
-rw-r--r-- | util/generic/overloaded_ut.cpp | 26 | ||||
-rw-r--r-- | util/generic/ptr.h | 88 | ||||
-rw-r--r-- | util/generic/serialized_enum.h | 2 | ||||
-rw-r--r-- | util/generic/set.h | 16 | ||||
-rw-r--r-- | util/generic/set_ut.cpp | 22 | ||||
-rw-r--r-- | util/generic/strbase.h | 60 | ||||
-rw-r--r-- | util/generic/string.h | 294 | ||||
-rw-r--r-- | util/generic/string_hash.h | 38 | ||||
-rw-r--r-- | util/generic/string_ut.cpp | 56 | ||||
-rw-r--r-- | util/generic/string_ut.h | 1054 | ||||
-rw-r--r-- | util/generic/variant.h | 18 |
24 files changed, 960 insertions, 960 deletions
diff --git a/util/generic/bitops.h b/util/generic/bitops.h index 2db15fc59b..9e31bf18d3 100644 --- a/util/generic/bitops.h +++ b/util/generic/bitops.h @@ -449,11 +449,11 @@ void SetBits(T& value, T bits) { value &= ~(maxValue << Offset); value |= bits << Offset; } - -inline constexpr ui64 NthBit64(int bit) { - return ui64(1) << bit; -} - -inline constexpr ui64 Mask64(int bits) { - return NthBit64(bits) - 1; -} + +inline constexpr ui64 NthBit64(int bit) { + return ui64(1) << bit; +} + +inline constexpr ui64 Mask64(int bits) { + return NthBit64(bits) - 1; +} diff --git a/util/generic/buffer.cpp b/util/generic/buffer.cpp index b92697e1d0..d0ba5fab85 100644 --- a/util/generic/buffer.cpp +++ b/util/generic/buffer.cpp @@ -1,6 +1,6 @@ -#include "buffer.h" -#include "mem_copy.h" -#include "string.h" +#include "buffer.h" +#include "mem_copy.h" +#include "string.h" #include "ymath.h" #include <util/system/sys_alloc.h> diff --git a/util/generic/cast.h b/util/generic/cast.h index 0d4a41f385..10278b6b62 100644 --- a/util/generic/cast.h +++ b/util/generic/cast.h @@ -5,7 +5,7 @@ #include <util/system/compat.h> #include <util/system/type_name.h> -#include <util/system/unaligned_mem.h> +#include <util/system/unaligned_mem.h> #include <util/system/yassert.h> #include <cstdlib> @@ -158,19 +158,19 @@ template <typename T> constexpr std::underlying_type_t<T> ToUnderlying(const T enum_) noexcept { return static_cast<std::underlying_type_t<T>>(enum_); } - -// std::bit_cast from c++20 -template <class TTarget, class TSource> -TTarget BitCast(const TSource& source) { - static_assert(sizeof(TSource) == sizeof(TTarget), "Size mismatch"); - static_assert(std::is_trivially_copyable<TSource>::value, "TSource is not trivially copyable"); - static_assert(std::is_trivial<TTarget>::value, "TTarget is not trivial"); - - // Support volatile qualifiers. - // ReadUnaligned does not work with volatile pointers, so cast away - // volatileness beforehand. - using TNonvolatileSource = std::remove_volatile_t<TSource>; - using TNonvolatileTarget = std::remove_volatile_t<TTarget>; - - return ReadUnaligned<TNonvolatileTarget>(&const_cast<const TNonvolatileSource&>(source)); -} + +// std::bit_cast from c++20 +template <class TTarget, class TSource> +TTarget BitCast(const TSource& source) { + static_assert(sizeof(TSource) == sizeof(TTarget), "Size mismatch"); + static_assert(std::is_trivially_copyable<TSource>::value, "TSource is not trivially copyable"); + static_assert(std::is_trivial<TTarget>::value, "TTarget is not trivial"); + + // Support volatile qualifiers. + // ReadUnaligned does not work with volatile pointers, so cast away + // volatileness beforehand. + using TNonvolatileSource = std::remove_volatile_t<TSource>; + using TNonvolatileTarget = std::remove_volatile_t<TTarget>; + + return ReadUnaligned<TNonvolatileTarget>(&const_cast<const TNonvolatileSource&>(source)); +} diff --git a/util/generic/cast_ut.cpp b/util/generic/cast_ut.cpp index 718a8de79d..1f73066ccd 100644 --- a/util/generic/cast_ut.cpp +++ b/util/generic/cast_ut.cpp @@ -8,7 +8,7 @@ class TGenericCastsTest: public TTestBase { UNIT_TEST(TestIntegralCast) UNIT_TEST(TestEnumCast) UNIT_TEST(TestToUnderlying) - UNIT_TEST(TestBitCast) + UNIT_TEST(TestBitCast) UNIT_TEST_SUITE_END(); private: @@ -81,32 +81,32 @@ private: UNIT_ASSERT_VALUES_EQUAL(static_cast<std::underlying_type_t<B>>(BM1), ToUnderlying(BM1)); UNIT_ASSERT_VALUES_EQUAL(static_cast<std::underlying_type_t<C>>(C::CM1), ToUnderlying(C::CM1)); } - - void TestBitCast() { - // Change sign of float - { + + void TestBitCast() { + // Change sign of float + { const float floatValue = 17.33f; - ui32 ui32Value = BitCast<ui32>(floatValue); - ui32Value ^= (ui32)1 << 31; - UNIT_ASSERT_VALUES_EQUAL(-floatValue, BitCast<float>(ui32Value)); - } - - // Unpack ui64 into a struct - { - const ui64 value = 0x1122334455667788; - struct TStruct { - ui32 a; - ui16 b; - ui8 c; - ui8 d; - }; - auto structValue = BitCast<TStruct>(value); - UNIT_ASSERT_VALUES_EQUAL(structValue.a, 0x55667788); - UNIT_ASSERT_VALUES_EQUAL(structValue.b, 0x3344); - UNIT_ASSERT_VALUES_EQUAL(structValue.c, 0x22); - UNIT_ASSERT_VALUES_EQUAL(structValue.d, 0x11); - } - } + ui32 ui32Value = BitCast<ui32>(floatValue); + ui32Value ^= (ui32)1 << 31; + UNIT_ASSERT_VALUES_EQUAL(-floatValue, BitCast<float>(ui32Value)); + } + + // Unpack ui64 into a struct + { + const ui64 value = 0x1122334455667788; + struct TStruct { + ui32 a; + ui16 b; + ui8 c; + ui8 d; + }; + auto structValue = BitCast<TStruct>(value); + UNIT_ASSERT_VALUES_EQUAL(structValue.a, 0x55667788); + UNIT_ASSERT_VALUES_EQUAL(structValue.b, 0x3344); + UNIT_ASSERT_VALUES_EQUAL(structValue.c, 0x22); + UNIT_ASSERT_VALUES_EQUAL(structValue.d, 0x11); + } + } }; UNIT_TEST_SUITE_REGISTRATION(TGenericCastsTest); diff --git a/util/generic/guid.cpp b/util/generic/guid.cpp index 8b907457bc..c56cfade60 100644 --- a/util/generic/guid.cpp +++ b/util/generic/guid.cpp @@ -42,7 +42,7 @@ TGUID TGUID::Create() { } void CreateGuid(TGUID* res) { - ui64* dw = reinterpret_cast<ui64*>(res->dw); + ui64* dw = reinterpret_cast<ui64*>(res->dw); WriteUnaligned<ui64>(&dw[0], RandomNumber<ui64>()); WriteUnaligned<ui64>(&dw[1], RandomNumber<ui64>()); diff --git a/util/generic/hash.h b/util/generic/hash.h index e46db21fa9..320691f0c9 100644 --- a/util/generic/hash.h +++ b/util/generic/hash.h @@ -1623,18 +1623,18 @@ public: } template <class TheKey> - bool contains(const TheKey& key) const { - return rep.find(key) != rep.end(); - } - bool contains(const key_type& key) const { - return rep.find(key) != rep.end(); - } - - template <class TheKey> - bool contains(const TheKey& key, insert_ctx& ins) { - return rep.find_i(key, ins) != rep.end(); - } - + bool contains(const TheKey& key) const { + return rep.find(key) != rep.end(); + } + bool contains(const key_type& key) const { + return rep.find(key) != rep.end(); + } + + template <class TheKey> + bool contains(const TheKey& key, insert_ctx& ins) { + return rep.find_i(key, ins) != rep.end(); + } + template <class TKey> T& operator[](const TKey& key) { insert_ctx ctx = nullptr; @@ -1935,10 +1935,10 @@ public: } template <class TheKey> - bool contains(const TheKey& key) const { - return rep.find(key) != rep.end(); - } - + bool contains(const TheKey& key) const { + return rep.find(key) != rep.end(); + } + template <class TKey> size_type count(const TKey& key) const { return rep.count(key); @@ -2021,9 +2021,9 @@ template <class Key, class T, class HF, class EqKey, class Alloc> inline bool operator!=(const THashMultiMap<Key, T, HF, EqKey, Alloc>& hm1, const THashMultiMap<Key, T, HF, EqKey, Alloc>& hm2) { return !(hm1 == hm2); } - -// Cannot name it just 'Hash' because it clashes with too many class members in the code. -template <class T> -size_t ComputeHash(const T& value) { - return THash<T>{}(value); -} + +// Cannot name it just 'Hash' because it clashes with too many class members in the code. +template <class T> +size_t ComputeHash(const T& value) { + return THash<T>{}(value); +} diff --git a/util/generic/hash.pxd b/util/generic/hash.pxd index 385c10d805..828c5e04ef 100644 --- a/util/generic/hash.pxd +++ b/util/generic/hash.pxd @@ -47,7 +47,7 @@ cdef extern from "util/generic/hash.h" nogil: void erase(iterator, iterator) except + size_t erase(T&) iterator find(T&) - bint contains(T&) + bint contains(T&) const_iterator const_find "find"(T&) pair[iterator, bint] insert(pair[T, U]) # XXX pair[T,U]& iterator insert(iterator, pair[T, U]) # XXX pair[T,U]& diff --git a/util/generic/hash_set.h b/util/generic/hash_set.h index e8088cf23b..f7cb6839c8 100644 --- a/util/generic/hash_set.h +++ b/util/generic/hash_set.h @@ -200,14 +200,14 @@ public: } template <class TheKey> - bool contains(const TheKey& key) const { - return rep.find(key) != rep.end(); - } - template <class TheKey> - bool contains(const TheKey& key, insert_ctx& ins) { - return rep.find_i(key, ins) != rep.end(); - } - + bool contains(const TheKey& key) const { + return rep.find(key) != rep.end(); + } + template <class TheKey> + bool contains(const TheKey& key, insert_ctx& ins) { + return rep.find_i(key, ins) != rep.end(); + } + template <class TKey> size_type count(const TKey& key) const { return rep.count(key); @@ -266,7 +266,7 @@ inline bool operator==(const THashSet<Value, HashFcn, EqualKey, Alloc>& hs1, con return false; } for (const auto& it : hs1) { - if (!hs2.contains(it)) { + if (!hs2.contains(it)) { return false; } } diff --git a/util/generic/hash_ut.cpp b/util/generic/hash_ut.cpp index 0551d58770..5804a53dca 100644 --- a/util/generic/hash_ut.cpp +++ b/util/generic/hash_ut.cpp @@ -177,9 +177,9 @@ void THashTest::TestHMap1() { m['x'] = "10"; // Correct mistake. UNIT_ASSERT(!strcmp(m['x'].c_str(), "10")); - UNIT_ASSERT(!m.contains('z')); + UNIT_ASSERT(!m.contains('z')); UNIT_ASSERT(!strcmp(m['z'].c_str(), "")); - UNIT_ASSERT(m.contains('z')); + UNIT_ASSERT(m.contains('z')); UNIT_ASSERT(m.count('z') == 1); auto p = m.insert(std::pair<const char, TString>('c', TString("100"))); @@ -377,34 +377,34 @@ void THashTest::TestHSetConstructorsAndAssignments() { UNIT_ASSERT_VALUES_EQUAL(2, c1.size()); UNIT_ASSERT_VALUES_EQUAL(2, c2.size()); - UNIT_ASSERT(c1.contains(100)); - UNIT_ASSERT(c2.contains(200)); + UNIT_ASSERT(c1.contains(100)); + UNIT_ASSERT(c2.contains(200)); container c3(std::move(c1)); UNIT_ASSERT_VALUES_EQUAL(0, c1.size()); UNIT_ASSERT_VALUES_EQUAL(2, c3.size()); - UNIT_ASSERT(c3.contains(100)); + UNIT_ASSERT(c3.contains(100)); c2.insert(300); c3 = c2; UNIT_ASSERT_VALUES_EQUAL(3, c2.size()); UNIT_ASSERT_VALUES_EQUAL(3, c3.size()); - UNIT_ASSERT(c3.contains(300)); + UNIT_ASSERT(c3.contains(300)); c2.insert(400); c3 = std::move(c2); UNIT_ASSERT_VALUES_EQUAL(0, c2.size()); UNIT_ASSERT_VALUES_EQUAL(4, c3.size()); - UNIT_ASSERT(c3.contains(400)); + UNIT_ASSERT(c3.contains(400)); container c4 = {1, 2, 3}; UNIT_ASSERT_VALUES_EQUAL(c4.size(), 3); - UNIT_ASSERT(c4.contains(1)); - UNIT_ASSERT(c4.contains(2)); - UNIT_ASSERT(c4.contains(3)); + UNIT_ASSERT(c4.contains(1)); + UNIT_ASSERT(c4.contains(2)); + UNIT_ASSERT(c4.contains(3)); } void THashTest::TestHSetSize() { @@ -1010,31 +1010,31 @@ void THashTest::TestHMMapEmplaceDirect() { void THashTest::TestHSetEmplace() { using hash_t = THashSet<TNonCopyableInt<0>, THash<int>, TEqualTo<int>>; hash_t hash; - UNIT_ASSERT(!hash.contains(0)); + UNIT_ASSERT(!hash.contains(0)); hash.emplace(0); - UNIT_ASSERT(hash.contains(0)); - UNIT_ASSERT(!hash.contains(1)); + UNIT_ASSERT(hash.contains(0)); + UNIT_ASSERT(!hash.contains(1)); } void THashTest::TestHSetEmplaceNoresize() { using hash_t = THashSet<TNonCopyableInt<0>, THash<int>, TEqualTo<int>>; hash_t hash; hash.reserve(1); - UNIT_ASSERT(!hash.contains(0)); + UNIT_ASSERT(!hash.contains(0)); hash.emplace_noresize(0); - UNIT_ASSERT(hash.contains(0)); - UNIT_ASSERT(!hash.contains(1)); + UNIT_ASSERT(hash.contains(0)); + UNIT_ASSERT(!hash.contains(1)); } void THashTest::TestHSetEmplaceDirect() { using hash_t = THashSet<TNonCopyableInt<0>, THash<int>, TEqualTo<int>>; hash_t hash; - UNIT_ASSERT(!hash.contains(0)); + UNIT_ASSERT(!hash.contains(0)); hash_t::insert_ctx ins; hash.find(0, ins); hash.emplace_direct(ins, 1); - UNIT_ASSERT(hash.contains(0)); - UNIT_ASSERT(!hash.contains(1)); + UNIT_ASSERT(hash.contains(0)); + UNIT_ASSERT(!hash.contains(1)); } void THashTest::TestNonCopyable() { @@ -1100,8 +1100,8 @@ void THashTest::TestReleaseNodes() { set.insert(i); } UNIT_ASSERT_VALUES_EQUAL(counters.Allocations, 7); - UNIT_ASSERT(set.contains(10)); - UNIT_ASSERT(!set.contains(0)); + UNIT_ASSERT(set.contains(10)); + UNIT_ASSERT(!set.contains(0)); set.basic_clear(); UNIT_ASSERT_VALUES_EQUAL(counters.Deallocations, 3); diff --git a/util/generic/hash_ut.pyx b/util/generic/hash_ut.pyx index ecf6dac2e6..3eb50fc950 100644 --- a/util/generic/hash_ut.pyx +++ b/util/generic/hash_ut.pyx @@ -24,8 +24,8 @@ class TestHash(unittest.TestCase): self.assertEqual(2, c1.size()) self.assertEqual(2, c2.size()) self.assertEqual(1, c1.at("one")) - self.assertTrue(c1.contains("two")) - self.assertTrue(c2.contains("one")) + self.assertTrue(c1.contains("two")) + self.assertTrue(c2.contains("one")) self.assertEqual(2, c2.at("two")) c2["three"] = 3 c1 = c2 diff --git a/util/generic/map.h b/util/generic/map.h index b5001b56c0..8a1533755d 100644 --- a/util/generic/map.h +++ b/util/generic/map.h @@ -22,9 +22,9 @@ public: return !this->empty(); } - inline bool contains(const K& key) const { - return this->find(key) != this->end(); - } + inline bool contains(const K& key) const { + return this->find(key) != this->end(); + } }; template <class K, class V, class Less, class A> @@ -38,7 +38,7 @@ public: return !this->empty(); } - inline bool contains(const K& key) const { - return this->find(key) != this->end(); - } + inline bool contains(const K& key) const { + return this->find(key) != this->end(); + } }; diff --git a/util/generic/map_ut.cpp b/util/generic/map_ut.cpp index 79e832b024..3fb0f800f4 100644 --- a/util/generic/map_ut.cpp +++ b/util/generic/map_ut.cpp @@ -468,7 +468,7 @@ Y_UNIT_TEST_SUITE(TYMapTest) { {"two", -2}, {"three", 3}, }; - UNIT_ASSERT(mm.contains("two")); + UNIT_ASSERT(mm.contains("two")); TMultiMap<TString, int> expected; expected.emplace("one", 1); expected.emplace("two", 2); @@ -485,12 +485,12 @@ Y_UNIT_TEST_SUITE(TYMapTest) { TMapInPool m(&pool); m.emplace(0, 1); - UNIT_ASSERT(m.contains(0)); + UNIT_ASSERT(m.contains(0)); UNIT_ASSERT_VALUES_EQUAL(1, m[0]); TMapInPool movedM = std::move(m); - UNIT_ASSERT(movedM.contains(0)); + UNIT_ASSERT(movedM.contains(0)); UNIT_ASSERT_VALUES_EQUAL(1, movedM[0]); } } diff --git a/util/generic/overloaded.h b/util/generic/overloaded.h index 96a97e44bc..c531f74fd8 100644 --- a/util/generic/overloaded.h +++ b/util/generic/overloaded.h @@ -3,9 +3,9 @@ /** * Construct an ad-hoc object with an overloaded `operator()`. * - * Typically used with lambdas to construct type-matching visitors for e.g. std::variant: + * Typically used with lambdas to construct type-matching visitors for e.g. std::variant: * ``` - * std::variant<int, void*, TString> var; + * std::variant<int, void*, TString> var; * Visit(TOverloaded{ * [](int val) { Cerr << "int: " << val; }, * [](void* val) { Cerr << "ptr: " << val; }, @@ -22,7 +22,7 @@ * For example, the following code will compile and run by casting all values to * double: * ``` - * std::variant<int, double, char> var; + * std::variant<int, double, char> var; * Visit(TOverloaded{ * [](double val) { Cerr << "dbl: " << val; }, * }, var); @@ -31,7 +31,7 @@ * If cases may be ambigous or specific type-matching logic is required, * a verbose `if constexpr`-based version would be preferred: * ``` - * std::variant<int, double, char> var; + * std::variant<int, double, char> var; * Visit([](auto&& val) { * using T = std::decay_t<decltype(val)>; * if constexpr (std::is_same_v<T, int>) { diff --git a/util/generic/overloaded_ut.cpp b/util/generic/overloaded_ut.cpp index f3d73895ad..57c3f284a6 100644 --- a/util/generic/overloaded_ut.cpp +++ b/util/generic/overloaded_ut.cpp @@ -28,13 +28,13 @@ Y_UNIT_TEST_SUITE(TOverloadedTest) { } Y_UNIT_TEST(VariantTest) { - std::variant<int, double, TType1> v = 5; + std::variant<int, double, TType1> v = 5; int res = 0; - std::visit(TOverloaded{ - [&](int val) { res = val; }, - [&](double) { res = -1; }, - [&](TType1) { res = -1; }}, - v); + std::visit(TOverloaded{ + [&](int val) { res = val; }, + [&](double) { res = -1; }, + [&](TType1) { res = -1; }}, + v); UNIT_ASSERT_VALUES_EQUAL(res, 5); } @@ -52,16 +52,16 @@ Y_UNIT_TEST_SUITE(TOverloadedTest) { } Y_UNIT_TEST(ImplicitConversionsTest) { - using TTestVariant = std::variant<int, double, char>; + using TTestVariant = std::variant<int, double, char>; // Purposefully exhibit inexact overload matched with implicit type // conversions // All cases implicitly cast to int auto matchAsInt = [](TTestVariant var) { - return std::visit(TOverloaded{ - [](int val) { return val; }, - }, var); + return std::visit(TOverloaded{ + [](int val) { return val; }, + }, var); }; UNIT_ASSERT_VALUES_EQUAL(matchAsInt(TTestVariant{17.77}), 17); @@ -70,9 +70,9 @@ Y_UNIT_TEST_SUITE(TOverloadedTest) { // All cases implicitly cast to double auto matchAsDouble = [](TTestVariant var) { - return std::visit(TOverloaded{ - [](double val) { return val; }, - }, var); + return std::visit(TOverloaded{ + [](double val) { return val; }, + }, var); }; UNIT_ASSERT_VALUES_EQUAL(matchAsDouble(TTestVariant{17.77}), 17.77); diff --git a/util/generic/ptr.h b/util/generic/ptr.h index 19db0e3ec5..f38a3e44ca 100644 --- a/util/generic/ptr.h +++ b/util/generic/ptr.h @@ -12,9 +12,9 @@ #include <util/system/yassert.h> #include <util/system/defaults.h> -template <class T, class U> -using TGuardConversion = typename std::enable_if_t<std::is_convertible<U*, T*>::value>; - +template <class T, class U> +using TGuardConversion = typename std::enable_if_t<std::is_convertible<U*, T*>::value>; + template <class T> inline void AssertTypeComplete() { // If compiler triggers this error from destructor of your class with @@ -242,7 +242,7 @@ public: { } - explicit THolder(T* t) noexcept + explicit THolder(T* t) noexcept : T_(t) { } @@ -252,7 +252,7 @@ public: { } - template <class U, class = TGuardConversion<T, U>> + template <class U, class = TGuardConversion<T, U>> inline THolder(TAutoPtr<U, D> t) noexcept : T_(t.Release()) { @@ -263,7 +263,7 @@ public: { } - template <class U, class = TGuardConversion<T, U>> + template <class U, class = TGuardConversion<T, U>> inline THolder(THolder<U, D>&& that) noexcept : T_(that.Release()) { @@ -346,7 +346,7 @@ private: template <typename T, typename... Args> [[nodiscard]] THolder<T> MakeHolder(Args&&... args) { - return THolder<T>(new T(std::forward<Args>(args)...)); + return THolder<T>(new T(std::forward<Args>(args)...)); } /* @@ -475,12 +475,12 @@ public: template <class T, class Ops> class TIntrusivePtr: public TPointerBase<TIntrusivePtr<T, Ops>, T> { - template <class U, class O> - friend class TIntrusivePtr; - - template <class U, class O> - friend class TIntrusiveConstPtr; + template <class U, class O> + friend class TIntrusivePtr; + template <class U, class O> + friend class TIntrusiveConstPtr; + public: struct TNoIncrement { }; @@ -517,20 +517,20 @@ public: // void Func(TIntrusivePtr<B>); // ... // Func(TIntrusivePtr<A>(new A)); // <--- compiler can't decide which version of Func to use - template <class U, class = TGuardConversion<T, U>> - inline TIntrusivePtr(const TIntrusivePtr<U>& p) noexcept + template <class U, class = TGuardConversion<T, U>> + inline TIntrusivePtr(const TIntrusivePtr<U>& p) noexcept : T_(p.Get()) { Ref(); } - template <class U, class = TGuardConversion<T, U>> - inline TIntrusivePtr(TIntrusivePtr<U>&& p) noexcept - : T_(p.T_) - { - p.T_ = nullptr; - } - + template <class U, class = TGuardConversion<T, U>> + inline TIntrusivePtr(TIntrusivePtr<U>&& p) noexcept + : T_(p.T_) + { + p.T_ = nullptr; + } + inline TIntrusivePtr(TIntrusivePtr&& p) noexcept : T_(nullptr) { @@ -637,26 +637,26 @@ public: Swap(p); } - inline TIntrusiveConstPtr(TIntrusivePtr<T> p) noexcept - : T_(p.T_) + inline TIntrusiveConstPtr(TIntrusivePtr<T> p) noexcept + : T_(p.T_) { - p.T_ = nullptr; + p.T_ = nullptr; } - template <class U, class = TGuardConversion<T, U>> - inline TIntrusiveConstPtr(const TIntrusiveConstPtr<U>& p) noexcept + template <class U, class = TGuardConversion<T, U>> + inline TIntrusiveConstPtr(const TIntrusiveConstPtr<U>& p) noexcept : T_(p.T_) { Ref(); } - template <class U, class = TGuardConversion<T, U>> - inline TIntrusiveConstPtr(TIntrusiveConstPtr<U>&& p) noexcept - : T_(p.T_) - { - p.T_ = nullptr; - } - + template <class U, class = TGuardConversion<T, U>> + inline TIntrusiveConstPtr(TIntrusiveConstPtr<U>&& p) noexcept + : T_(p.T_) + { + p.T_ = nullptr; + } + inline TIntrusiveConstPtr& operator=(TIntrusiveConstPtr p) noexcept { p.Swap(*this); @@ -816,7 +816,7 @@ public: { } - template <class TT, class = TGuardConversion<T, TT>> + template <class TT, class = TGuardConversion<T, TT>> inline TSharedPtr(THolder<TT>&& t) { Init(t); } @@ -839,7 +839,7 @@ public: Swap(t); } - template <class TT, class = TGuardConversion<T, TT>> + template <class TT, class = TGuardConversion<T, TT>> inline TSharedPtr(const TSharedPtr<TT, C, D>& t) noexcept : T_(t.T_) , C_(t.C_) @@ -847,15 +847,15 @@ public: Ref(); } - template <class TT, class = TGuardConversion<T, TT>> - inline TSharedPtr(TSharedPtr<TT, C, D>&& t) noexcept - : T_(t.T_) - , C_(t.C_) - { - t.T_ = nullptr; - t.C_ = nullptr; - } - + template <class TT, class = TGuardConversion<T, TT>> + inline TSharedPtr(TSharedPtr<TT, C, D>&& t) noexcept + : T_(t.T_) + , C_(t.C_) + { + t.T_ = nullptr; + t.C_ = nullptr; + } + inline TSharedPtr& operator=(TSharedPtr t) noexcept { t.Swap(*this); diff --git a/util/generic/serialized_enum.h b/util/generic/serialized_enum.h index 79df2bac22..74228a0609 100644 --- a/util/generic/serialized_enum.h +++ b/util/generic/serialized_enum.h @@ -375,7 +375,7 @@ namespace NEnumSerializationRuntime { } bool contains(const TEnumType key) const { - return Ref.contains(this->CastToRepresentationType(key)); + return Ref.contains(this->CastToRepresentationType(key)); } TIterator find(const TEnumType key) const { diff --git a/util/generic/set.h b/util/generic/set.h index 4c437ca26f..3573ee9f8e 100644 --- a/util/generic/set.h +++ b/util/generic/set.h @@ -20,9 +20,9 @@ public: } template <class TheKey> - inline bool contains(const TheKey& key) const { - return this->find(key) != this->end(); - } + inline bool contains(const TheKey& key) const { + return this->find(key) != this->end(); + } }; template <class K, class L, class A> @@ -34,9 +34,9 @@ public: inline explicit operator bool() const noexcept { return !this->empty(); } - - template <class TheKey> - inline bool contains(const TheKey& key) const { - return this->find(key) != this->end(); - } + + template <class TheKey> + inline bool contains(const TheKey& key) const { + return this->find(key) != this->end(); + } }; diff --git a/util/generic/set_ut.cpp b/util/generic/set_ut.cpp index d2769d327f..3308651a51 100644 --- a/util/generic/set_ut.cpp +++ b/util/generic/set_ut.cpp @@ -73,20 +73,20 @@ Y_UNIT_TEST_SUITE(YSetTest) { Y_UNIT_TEST(TestHas) { TSet<int> s; - UNIT_ASSERT(!s.contains(0)); + UNIT_ASSERT(!s.contains(0)); TSet<int> const& crs = s; - UNIT_ASSERT(!crs.contains(0)); + UNIT_ASSERT(!crs.contains(0)); s.insert(1); s.insert(42); s.insert(100); s.insert(2); - UNIT_ASSERT(s.contains(1)); - UNIT_ASSERT(s.contains(2)); - UNIT_ASSERT(s.contains(42)); - UNIT_ASSERT(s.contains(100)); + UNIT_ASSERT(s.contains(1)); + UNIT_ASSERT(s.contains(2)); + UNIT_ASSERT(s.contains(42)); + UNIT_ASSERT(s.contains(100)); } Y_UNIT_TEST(TestBounds) { @@ -203,28 +203,28 @@ Y_UNIT_TEST_SUITE(YSetTest) { UNIT_ASSERT_VALUES_EQUAL(2, c1.size()); UNIT_ASSERT_VALUES_EQUAL(2, c2.size()); - UNIT_ASSERT(c1.contains(100)); - UNIT_ASSERT(c2.contains(200)); + UNIT_ASSERT(c1.contains(100)); + UNIT_ASSERT(c2.contains(200)); container c3(std::move(c1)); UNIT_ASSERT_VALUES_EQUAL(0, c1.size()); UNIT_ASSERT_VALUES_EQUAL(2, c3.size()); - UNIT_ASSERT(c3.contains(100)); + UNIT_ASSERT(c3.contains(100)); c2.insert(300); c3 = c2; UNIT_ASSERT_VALUES_EQUAL(3, c2.size()); UNIT_ASSERT_VALUES_EQUAL(3, c3.size()); - UNIT_ASSERT(c3.contains(300)); + UNIT_ASSERT(c3.contains(300)); c2.insert(400); c3 = std::move(c2); UNIT_ASSERT_VALUES_EQUAL(0, c2.size()); UNIT_ASSERT_VALUES_EQUAL(4, c3.size()); - UNIT_ASSERT(c3.contains(400)); + UNIT_ASSERT(c3.contains(400)); } { diff --git a/util/generic/strbase.h b/util/generic/strbase.h index ab39fc7537..425755cfbc 100644 --- a/util/generic/strbase.h +++ b/util/generic/strbase.h @@ -37,7 +37,7 @@ namespace NStringPrivate { template <typename TDerived, typename TCharType, typename TTraitsType = std::char_traits<TCharType>> class TStringBase { using TStringView = std::basic_string_view<TCharType>; - using TStringViewWithTraits = std::basic_string_view<TCharType, TTraitsType>; + using TStringViewWithTraits = std::basic_string_view<TCharType, TTraitsType>; public: using TChar = TCharType; @@ -115,11 +115,11 @@ public: template <class TCharTraits> inline constexpr operator std::basic_string_view<TCharType, TCharTraits>() const { - return std::basic_string_view<TCharType, TCharTraits>(data(), size()); + return std::basic_string_view<TCharType, TCharTraits>(data(), size()); } template <class TCharTraits, class Allocator> - inline explicit operator std::basic_string<TCharType, TCharTraits, Allocator>() const { + inline explicit operator std::basic_string<TCharType, TCharTraits, Allocator>() const { return std::basic_string<TCharType, TCharTraits, Allocator>(Ptr(), Len()); } @@ -219,17 +219,17 @@ private: public: // ~~~ Comparison ~~~ : FAMILY0(int, compare) static int compare(const TSelf& s1, const TSelf& s2) noexcept { - return s1.AsStringView().compare(s2.AsStringView()); + return s1.AsStringView().compare(s2.AsStringView()); } static int compare(const TCharType* p, const TSelf& s2) noexcept { - TCharType null{0}; - return TStringViewWithTraits(p ? p : &null).compare(s2.AsStringView()); + TCharType null{0}; + return TStringViewWithTraits(p ? p : &null).compare(s2.AsStringView()); } static int compare(const TSelf& s1, const TCharType* p) noexcept { - TCharType null{0}; - return s1.AsStringView().compare(p ? p : &null); + TCharType null{0}; + return s1.AsStringView().compare(p ? p : &null); } static int compare(const TStringView s1, const TStringView s2) noexcept { @@ -258,7 +258,7 @@ public: } static bool equal(const TSelf& s1, const TSelf& s2) noexcept { - return s1.AsStringView() == s2.AsStringView(); + return s1.AsStringView() == s2.AsStringView(); } static bool equal(const TSelf& s1, const TCharType* p) noexcept { @@ -266,7 +266,7 @@ public: return s1.Len() == 0; } - return s1.AsStringView() == p; + return s1.AsStringView() == p; } static bool equal(const TCharType* p, const TSelf& s2) noexcept { @@ -274,7 +274,7 @@ public: } static bool equal(const TStringView s1, const TStringView s2) noexcept { - return TStringViewWithTraits{s1.data(), s1.size()} == TStringViewWithTraits{s2.data(), s2.size()}; + return TStringViewWithTraits{s1.data(), s1.size()} == TStringViewWithTraits{s2.data(), s2.size()}; } template <class T> @@ -295,11 +295,11 @@ public: } static inline bool StartsWith(const TCharType* what, size_t whatLen, const TCharType* with, size_t withLen) noexcept { - return withLen <= whatLen && TStringViewWithTraits(what, withLen) == TStringViewWithTraits(with, withLen); + return withLen <= whatLen && TStringViewWithTraits(what, withLen) == TStringViewWithTraits(with, withLen); } static inline bool EndsWith(const TCharType* what, size_t whatLen, const TCharType* with, size_t withLen) noexcept { - return withLen <= whatLen && TStringViewWithTraits(what + whatLen - withLen, withLen) == TStringViewWithTraits(with, withLen); + return withLen <= whatLen && TStringViewWithTraits(what + whatLen - withLen, withLen) == TStringViewWithTraits(with, withLen); } inline bool StartsWith(const TCharType* s, size_t n) const noexcept { @@ -311,7 +311,7 @@ public: } inline bool StartsWith(TCharType ch) const noexcept { - return !empty() && TTraits::eq(*Ptr(), ch); + return !empty() && TTraits::eq(*Ptr(), ch); } inline bool EndsWith(const TCharType* s, size_t n) const noexcept { @@ -323,7 +323,7 @@ public: } inline bool EndsWith(TCharType ch) const noexcept { - return !empty() && TTraits::eq(Ptr()[Len() - 1], ch); + return !empty() && TTraits::eq(Ptr()[Len() - 1], ch); } template <typename TDerived2, typename TTraits2> @@ -449,30 +449,30 @@ public: * @return Position of the substring inside this string, or `npos` if not found. */ inline size_t find(const TStringView s, size_t pos = 0) const noexcept { - return find(s.data(), pos, s.size()); + return find(s.data(), pos, s.size()); } inline size_t find(const TCharType* s, size_t pos, size_t count) const noexcept { - return AsStringView().find(s, pos, count); + return AsStringView().find(s, pos, count); } inline size_t find(TCharType c, size_t pos = 0) const noexcept { - return AsStringView().find(c, pos); + return AsStringView().find(c, pos); } inline size_t rfind(TCharType c) const noexcept { - return AsStringView().rfind(c); + return AsStringView().rfind(c); } inline size_t rfind(TCharType c, size_t pos) const noexcept { - if (pos == 0) { - return npos; + if (pos == 0) { + return npos; } - return AsStringView().rfind(c, pos - 1); + return AsStringView().rfind(c, pos - 1); } inline size_t rfind(const TStringView str, size_t pos = npos) const { - return AsStringView().rfind(str.data(), pos, str.size()); + return AsStringView().rfind(str.data(), pos, str.size()); } //~~~~Contains~~~~ @@ -505,7 +505,7 @@ public: } inline size_t find_first_of(const TStringView set, size_t pos) const noexcept { - return AsStringView().find_first_of(set.data(), pos, set.size()); + return AsStringView().find_first_of(set.data(), pos, set.size()); } inline size_t find_first_not_of(TCharType c) const noexcept { @@ -521,7 +521,7 @@ public: } inline size_t find_first_not_of(const TStringView set, size_t pos) const noexcept { - return AsStringView().find_first_not_of(set.data(), pos, set.size()); + return AsStringView().find_first_not_of(set.data(), pos, set.size()); } inline size_t find_last_of(TCharType c, size_t pos = npos) const noexcept { @@ -533,11 +533,11 @@ public: } inline size_t find_last_of(const TCharType* set, size_t pos, size_t n) const noexcept { - return AsStringView().find_last_of(set, pos, n); + return AsStringView().find_last_of(set, pos, n); } inline size_t find_last_not_of(TCharType c, size_t pos = npos) const noexcept { - return AsStringView().find_last_not_of(c, pos); + return AsStringView().find_last_not_of(c, pos); } inline size_t find_last_not_of(const TStringView set, size_t pos = npos) const noexcept { @@ -545,7 +545,7 @@ public: } inline size_t find_last_not_of(const TCharType* set, size_t pos, size_t n) const noexcept { - return AsStringView().find_last_not_of(set, pos, n); + return AsStringView().find_last_not_of(set, pos, n); } inline size_t copy(TCharType* pc, size_t n, size_t pos) const { @@ -581,8 +581,8 @@ public: private: using GenericFinder = const TCharType* (*)(const TCharType*, size_t, const TCharType*, size_t); - TStringViewWithTraits AsStringView() const { - return static_cast<TStringViewWithTraits>(*this); + TStringViewWithTraits AsStringView() const { + return static_cast<TStringViewWithTraits>(*this); } constexpr inline const TCharType* Ptr() const noexcept { diff --git a/util/generic/string.h b/util/generic/string.h index 8cd8aa6917..e69704a79b 100644 --- a/util/generic/string.h +++ b/util/generic/string.h @@ -18,7 +18,7 @@ #include "singleton.h" #include "strbase.h" #include "strbuf.h" -#include "string_hash.h" +#include "string_hash.h" #if defined(address_sanitizer_enabled) || defined(thread_sanitizer_enabled) #include "hide_ptr.h" @@ -153,7 +153,7 @@ private: TStringType& S_; size_t Pos_; }; -#endif +#endif template <typename TCharType, typename TTraits> class TBasicString: public TStringBase<TBasicString<TCharType, TTraits>, TCharType, TTraits> { @@ -161,14 +161,14 @@ public: // TODO: Move to private section using TBase = TStringBase<TBasicString, TCharType, TTraits>; using TStringType = std::basic_string<TCharType, TTraits>; -#ifdef TSTRING_IS_STD_STRING +#ifdef TSTRING_IS_STD_STRING using TStorage = TStringType; using reference = typename TStorage::reference; -#else +#else using TStdStr = TStdString<TStringType>; using TStorage = TIntrusivePtr<TStdStr, TStringPtrOps<TStdStr>>; using reference = TBasicCharRef<TBasicString>; -#endif +#endif using char_type = TCharType; // TODO: DROP using value_type = TCharType; using traits_type = TTraits; @@ -188,16 +188,16 @@ public: size_t Size; }; - static size_t max_size() noexcept { + static size_t max_size() noexcept { static size_t res = TStringType().max_size(); return res; } protected: -#ifdef TSTRING_IS_STD_STRING - TStorage Storage_; -#else +#ifdef TSTRING_IS_STD_STRING + TStorage Storage_; +#else TStorage S_; template <typename... A> @@ -259,11 +259,11 @@ public: inline reference operator[](size_t pos) noexcept { Y_ASSERT(pos <= length()); -#ifdef TSTRING_IS_STD_STRING - return Storage_[pos]; -#else +#ifdef TSTRING_IS_STD_STRING + return Storage_[pos]; +#else return reference(*this, pos); -#endif +#endif } using TBase::back; @@ -271,15 +271,15 @@ public: inline reference back() noexcept { Y_ASSERT(!this->empty()); -#ifdef TSTRING_IS_STD_STRING - return Storage_.back(); -#else +#ifdef TSTRING_IS_STD_STRING + return Storage_.back(); +#else if (Y_UNLIKELY(this->empty())) { return reference(*this, 0); } return reference(*this, length() - 1); -#endif +#endif } using TBase::front; @@ -287,11 +287,11 @@ public: inline reference front() noexcept { Y_ASSERT(!this->empty()); -#ifdef TSTRING_IS_STD_STRING - return Storage_.front(); -#else +#ifdef TSTRING_IS_STD_STRING + return Storage_.front(); +#else return reference(*this, 0); -#endif +#endif } inline size_t length() const noexcept { @@ -333,80 +333,80 @@ public: using TBase::rend; //!< const_reverse_iterator TStringBase::rend() const inline size_t capacity() const noexcept { -#ifdef TSTRING_IS_STD_STRING - return Storage_.capacity(); -#else +#ifdef TSTRING_IS_STD_STRING + return Storage_.capacity(); +#else if (S_->IsNull()) { return 0; } return S_->capacity(); -#endif +#endif } TCharType* Detach() { -#ifdef TSTRING_IS_STD_STRING - return Storage_.data(); -#else +#ifdef TSTRING_IS_STD_STRING + return Storage_.data(); +#else if (Y_UNLIKELY(!IsDetached())) { Clone(); } return (TCharType*)S_->data(); -#endif +#endif } bool IsDetached() const { -#ifdef TSTRING_IS_STD_STRING - return true; -#else +#ifdef TSTRING_IS_STD_STRING + return true; +#else return 1 == RefCount(); -#endif +#endif } // ~~~ Size and capacity ~~~ TBasicString& resize(size_t n, TCharType c = ' ') { // remove or append MutRef().resize(n, c); - - return *this; + + return *this; } // ~~~ Constructor ~~~ : FAMILY0(,TBasicString) TBasicString() noexcept -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING : S_(Construct()) -#endif +#endif { } inline explicit TBasicString(::NDetail::TReserveTag rt) -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING : S_(Construct()) -#endif +#endif { reserve(rt.Capacity); } inline TBasicString(const TBasicString& s) -#ifdef TSTRING_IS_STD_STRING - : Storage_(s.Storage_) -#else +#ifdef TSTRING_IS_STD_STRING + : Storage_(s.Storage_) +#else : S_(s.S_) -#endif +#endif { } inline TBasicString(TBasicString&& s) noexcept -#ifdef TSTRING_IS_STD_STRING - : Storage_(std::move(s.Storage_)) -#else +#ifdef TSTRING_IS_STD_STRING + : Storage_(std::move(s.Storage_)) +#else : S_(Construct()) -#endif +#endif { #ifdef TSTRING_IS_STD_STRING #else s.swap(*this); -#endif +#endif } template <typename T, typename A> @@ -426,41 +426,41 @@ public: } TBasicString(const TBasicString& s, size_t pos, size_t n) Y_NOEXCEPT -#ifdef TSTRING_IS_STD_STRING - : Storage_(s.Storage_, pos, n) +#ifdef TSTRING_IS_STD_STRING + : Storage_(s.Storage_, pos, n) #else : S_(n ? Construct(s, pos, n) : Construct()) -#endif - { +#endif + { } - TBasicString(const TCharType* pc) + TBasicString(const TCharType* pc) : TBasicString(pc, TBase::StrLen(pc)) - { + { } // TODO thegeorg@: uncomment and fix clients // TBasicString(std::nullptr_t) = delete; - TBasicString(const TCharType* pc, size_t n) -#ifdef TSTRING_IS_STD_STRING - : Storage_(pc, n) + TBasicString(const TCharType* pc, size_t n) +#ifdef TSTRING_IS_STD_STRING + : Storage_(pc, n) #else : S_(n ? Construct(pc, n) : Construct()) -#endif - { +#endif + { } TBasicString(std::nullptr_t, size_t) = delete; - TBasicString(const TCharType* pc, size_t pos, size_t n) + TBasicString(const TCharType* pc, size_t pos, size_t n) : TBasicString(pc + pos, n) - { + { } #ifdef TSTRING_IS_STD_STRING explicit TBasicString(TExplicitType<TCharType> c) { - Storage_.push_back(c); + Storage_.push_back(c); } -#else +#else explicit TBasicString(TExplicitType<TCharType> c) : TBasicString(&c.Value(), 1) { @@ -469,15 +469,15 @@ public: : TBasicString(&c, 1) { } -#endif +#endif - TBasicString(size_t n, TCharType c) -#ifdef TSTRING_IS_STD_STRING - : Storage_(n, c) + TBasicString(size_t n, TCharType c) +#ifdef TSTRING_IS_STD_STRING + : Storage_(n, c) #else : S_(Construct(n, c)) -#endif - { +#endif + { } /** @@ -489,13 +489,13 @@ public: TBasicString(TUninitialized uninitialized) { #if !defined(TSTRING_IS_STD_STRING) S_ = Construct(); -#endif +#endif ReserveAndResize(uninitialized.Size); } - TBasicString(const TCharType* b, const TCharType* e) + TBasicString(const TCharType* b, const TCharType* e) : TBasicString(b, e - b) - { + { } explicit TBasicString(const TBasicStringBuf<TCharType, TTraits> s) @@ -504,14 +504,14 @@ public: } template <typename Traits> - explicit inline TBasicString(const std::basic_string_view<TCharType, Traits>& s) + explicit inline TBasicString(const std::basic_string_view<TCharType, Traits>& s) : TBasicString(s.data(), s.size()) - { + { } /** - * WARN: - * Certain invocations of this method will result in link-time error. + * WARN: + * Certain invocations of this method will result in link-time error. * You are free to implement corresponding methods in string.cpp if you need them. */ static TBasicString FromAscii(const ::TStringBuf& s) { @@ -562,9 +562,9 @@ private: public: inline void clear() noexcept { -#ifdef TSTRING_IS_STD_STRING - Storage_.clear(); -#else +#ifdef TSTRING_IS_STD_STRING + Storage_.clear(); +#else if (IsDetached()) { S_->clear(); @@ -572,7 +572,7 @@ public: } Construct().Swap(S_); -#endif +#endif } template <typename... R> @@ -655,8 +655,8 @@ public: } /** - * WARN: - * Certain invocations of this method will result in link-time error. + * WARN: + * Certain invocations of this method will result in link-time error. * You are free to implement corresponding methods in string.cpp if you need them. */ auto AssignAscii(const ::TStringBuf& s) { @@ -720,20 +720,20 @@ public: inline TBasicString& append(const TBasicString& s) { MutRef().append(s.ConstRef()); - - return *this; + + return *this; } inline TBasicString& append(const TBasicString& s, size_t pos, size_t n) { MutRef().append(s.ConstRef(), pos, n); - - return *this; + + return *this; } inline TBasicString& append(const TCharType* pc) Y_NOEXCEPT { MutRef().append(pc); - - return *this; + + return *this; } inline TBasicString& append(TCharType c) { @@ -744,14 +744,14 @@ public: inline TBasicString& append(const TCharType* first, const TCharType* last) { MutRef().append(first, last); - - return *this; + + return *this; } inline TBasicString& append(const TCharType* pc, size_t len) { MutRef().append(pc, len); - - return *this; + + return *this; } inline void ReserveAndResize(size_t len) { @@ -786,12 +786,12 @@ public: } TBasicString& append(const TCharType* pc, size_t pos, size_t n, size_t pc_len = TBase::npos) { - return append(pc + pos, Min(n, pc_len - pos)); + return append(pc + pos, Min(n, pc_len - pos)); } /** - * WARN: - * Certain invocations of this method will result in link-time error. + * WARN: + * Certain invocations of this method will result in link-time error. * You are free to implement corresponding methods in string.cpp if you need them. */ TBasicString& AppendAscii(const ::TStringBuf& s); @@ -836,8 +836,8 @@ public: operator const TStringType&() const noexcept { return this->ConstRef(); - } - + } + operator TStringType&() { return this->MutRef(); } @@ -879,7 +879,7 @@ public: s2.prepend(s1); return std::move(s2); } -#endif +#endif s1 += s2; return std::move(s1); } @@ -948,32 +948,32 @@ public: // ~~~ Prepending ~~~ : FAMILY0(TBasicString&, prepend); TBasicString& prepend(const TBasicString& s) { MutRef().insert(0, s.ConstRef()); - - return *this; + + return *this; } TBasicString& prepend(const TBasicString& s, size_t pos, size_t n) { MutRef().insert(0, s.ConstRef(), pos, n); - - return *this; + + return *this; } TBasicString& prepend(const TCharType* pc) { MutRef().insert(0, pc); - - return *this; + + return *this; } TBasicString& prepend(size_t n, TCharType c) { MutRef().insert(size_t(0), n, c); - - return *this; + + return *this; } TBasicString& prepend(TCharType c) { MutRef().insert(size_t(0), 1, c); - - return *this; + + return *this; } TBasicString& prepend(const TBasicStringBuf<TCharType, TTraits> s, size_t spos = 0, size_t sn = TBase::npos) { @@ -983,42 +983,42 @@ public: // ~~~ Insertion ~~~ : FAMILY1(TBasicString&, insert, size_t pos); TBasicString& insert(size_t pos, const TBasicString& s) { MutRef().insert(pos, s.ConstRef()); - - return *this; + + return *this; } TBasicString& insert(size_t pos, const TBasicString& s, size_t pos1, size_t n1) { MutRef().insert(pos, s.ConstRef(), pos1, n1); - - return *this; + + return *this; } TBasicString& insert(size_t pos, const TCharType* pc) { MutRef().insert(pos, pc); - - return *this; + + return *this; } TBasicString& insert(size_t pos, const TCharType* pc, size_t len) { MutRef().insert(pos, pc, len); - - return *this; + + return *this; } TBasicString& insert(const_iterator pos, const_iterator b, const_iterator e) { -#ifdef TSTRING_IS_STD_STRING - Storage_.insert(Storage_.begin() + this->off(pos), b, e); - - return *this; -#else +#ifdef TSTRING_IS_STD_STRING + Storage_.insert(Storage_.begin() + this->off(pos), b, e); + + return *this; +#else return insert(this->off(pos), b, e - b); -#endif +#endif } TBasicString& insert(size_t pos, size_t n, TCharType c) { MutRef().insert(pos, n, c); - - return *this; + + return *this; } TBasicString& insert(const_iterator pos, size_t len, TCharType ch) { @@ -1031,8 +1031,8 @@ public: TBasicString& insert(size_t pos, const TBasicStringBuf<TCharType, TTraits> s, size_t spos = 0, size_t sn = TBase::npos) { MutRef().insert(pos, s, spos, sn); - - return *this; + + return *this; } // ~~~ Removing ~~~ @@ -1040,8 +1040,8 @@ public: if (pos < length()) { MutRef().erase(pos, n); } - - return *this; + + return *this; } TBasicString& remove(size_t pos = 0) Y_NOEXCEPT { @@ -1054,8 +1054,8 @@ public: TBasicString& erase(size_t pos = 0, size_t n = TBase::npos) Y_NOEXCEPT { MutRef().erase(pos, n); - - return *this; + + return *this; } TBasicString& erase(const_iterator b, const_iterator e) Y_NOEXCEPT { @@ -1068,10 +1068,10 @@ public: TBasicString& pop_back() Y_NOEXCEPT { Y_ASSERT(!this->empty()); - + MutRef().pop_back(); - return *this; + return *this; } // ~~~ replacement ~~~ : FAMILY2(TBasicString&, replace, size_t pos, size_t n); @@ -1118,11 +1118,11 @@ public: } void swap(TBasicString& s) noexcept { -#ifdef TSTRING_IS_STD_STRING - std::swap(Storage_, s.Storage_); -#else +#ifdef TSTRING_IS_STD_STRING + std::swap(Storage_, s.Storage_); +#else S_.Swap(s.S_); -#endif +#endif } /** @@ -1166,15 +1166,15 @@ public: bool changed = false; for (size_t i = pos; i != pos + n; ++i) { -#ifdef TSTRING_IS_STD_STRING - auto c = f(i, Storage_[i]); - - if (c != Storage_[i]) { - changed = true; - - Storage_[i] = c; - } -#else +#ifdef TSTRING_IS_STD_STRING + auto c = f(i, Storage_[i]); + + if (c != Storage_[i]) { + changed = true; + + Storage_[i] = c; + } +#else auto c = f(i, data()[i]); if (c != data()[i]) { if (!changed) { @@ -1184,7 +1184,7 @@ public: begin()[i] = c; } -#endif +#endif } return changed; @@ -1221,7 +1221,7 @@ namespace std { using argument_type = TString; using result_type = size_t; inline result_type operator()(argument_type const& s) const noexcept { - return NHashPrivate::ComputeStringHash(s.data(), s.size()); + return NHashPrivate::ComputeStringHash(s.data(), s.size()); } }; } diff --git a/util/generic/string_hash.h b/util/generic/string_hash.h index b949c7a2d9..23f1798c68 100644 --- a/util/generic/string_hash.h +++ b/util/generic/string_hash.h @@ -1,21 +1,21 @@ -#pragma once - -#include <cstddef> - -// reduce code bloat and cycled includes, declare functions here -#if defined(_64_) && !defined(NO_CITYHASH) -ui64 CityHash64(const char* buf, size_t len) noexcept; -#else -size_t MurmurHashSizeT(const char* buf, size_t len) noexcept; -#endif - -namespace NHashPrivate { - template <typename C> - size_t ComputeStringHash(const C* ptr, size_t size) noexcept { -#if defined(_64_) && !defined(NO_CITYHASH) +#pragma once + +#include <cstddef> + +// reduce code bloat and cycled includes, declare functions here +#if defined(_64_) && !defined(NO_CITYHASH) +ui64 CityHash64(const char* buf, size_t len) noexcept; +#else +size_t MurmurHashSizeT(const char* buf, size_t len) noexcept; +#endif + +namespace NHashPrivate { + template <typename C> + size_t ComputeStringHash(const C* ptr, size_t size) noexcept { +#if defined(_64_) && !defined(NO_CITYHASH) return CityHash64((const char*)ptr, size * sizeof(C)); -#else +#else return MurmurHashSizeT((const char*)ptr, size * sizeof(C)); -#endif - } -} +#endif + } +} diff --git a/util/generic/string_ut.cpp b/util/generic/string_ut.cpp index ac82e9091d..c5f3531fa6 100644 --- a/util/generic/string_ut.cpp +++ b/util/generic/string_ut.cpp @@ -1,24 +1,24 @@ #include "deque.h" -#include "strbuf.h" -#include "string_ut.h" +#include "strbuf.h" +#include "string_ut.h" #include "vector.h" #include "yexception.h" #include <util/charset/wide.h> #include <util/str_stl.h> -#include <util/stream/output.h> -#include <util/string/subst.h> +#include <util/stream/output.h> +#include <util/string/subst.h> #include <string> #include <sstream> #include <algorithm> #include <stdexcept> -#ifdef TSTRING_IS_STD_STRING -static_assert(sizeof(TString) == sizeof(std::string), "expect sizeof(TString) == sizeof(std::string)"); -#else +#ifdef TSTRING_IS_STD_STRING +static_assert(sizeof(TString) == sizeof(std::string), "expect sizeof(TString) == sizeof(std::string)"); +#else static_assert(sizeof(TString) == sizeof(const char*), "expect sizeof(TString) == sizeof(const char*)"); -#endif +#endif class TStringTestZero: public TTestBase { UNIT_TEST_SUITE(TStringTestZero); @@ -50,7 +50,7 @@ public: TString copy = s; copy.replace(copy.size() - 1, 1, "z"); UNIT_ASSERT(s != copy); - copy.replace(copy.size() - 1, 1, "\0", 0, 1); + copy.replace(copy.size() - 1, 1, "\0", 0, 1); UNIT_ASSERT(s == copy); TString prefix(data, 5); @@ -70,9 +70,9 @@ UNIT_TEST_SUITE_REGISTRATION(TStringTestZero); template <typename TStringType, typename TTestData> class TStringStdTestImpl { - using TChar = typename TStringType::char_type; - using TTraits = typename TStringType::traits_type; - using TView = std::basic_string_view<TChar, TTraits>; + using TChar = typename TStringType::char_type; + using TTraits = typename TStringType::traits_type; + using TView = std::basic_string_view<TChar, TTraits>; TTestData Data_; @@ -121,7 +121,7 @@ protected: s.reserve(10); #ifdef TSTRING_IS_STD_STRING - UNIT_ASSERT(s.capacity() >= 64); + UNIT_ASSERT(s.capacity() >= 64); #else UNIT_ASSERT(s.capacity() >= 256 && s.data() == data); #endif @@ -147,7 +147,7 @@ protected: UNIT_ASSERT(s.capacity() >= 64 && s.capacity() < 128 && s.data() != data); UNIT_ASSERT(s.IsDetached()); #endif -#endif +#endif } void short_string() { @@ -511,7 +511,7 @@ protected: void copy() { TStringType s(Data_.foo()); - TChar dest[4]; + TChar dest[4]; dest[0] = dest[1] = dest[2] = dest[3] = 1; s.copy(dest, 4); int pos = 0; @@ -712,7 +712,7 @@ protected: UNIT_ASSERT(str == Data.This_This_is_test_StringT_for_StringT_calls()); #if !defined(STLPORT) || defined(_STLP_MEMBER_TEMPLATES) - deque<TChar> cdeque; + deque<TChar> cdeque; cdeque.push_back(*Data.I()); str.replace(str.begin(), str.begin() + 11, cdeque.begin(), cdeque.end()); UNIT_ASSERT(str == Data.Is_test_StringT_for_StringT_calls()); @@ -727,9 +727,9 @@ public: UNIT_TEST(TestMaxSize); UNIT_TEST(TestConstructors); UNIT_TEST(TestReplace); -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING UNIT_TEST(TestRefCount); -#endif +#endif UNIT_TEST(TestFind); UNIT_TEST(TestContains); UNIT_TEST(TestOperators); @@ -741,9 +741,9 @@ public: UNIT_TEST(TestCopy); UNIT_TEST(TestStrCpy); UNIT_TEST(TestPrefixSuffix); -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING UNIT_TEST(TestCharRef); -#endif +#endif UNIT_TEST(TestBack) UNIT_TEST(TestFront) UNIT_TEST(TestIterators); @@ -788,9 +788,9 @@ public: UNIT_TEST_SUITE(TWideStringTest); UNIT_TEST(TestConstructors); UNIT_TEST(TestReplace); -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING UNIT_TEST(TestRefCount); -#endif +#endif UNIT_TEST(TestFind); UNIT_TEST(TestContains); UNIT_TEST(TestOperators); @@ -803,9 +803,9 @@ public: UNIT_TEST(TestCopy); UNIT_TEST(TestStrCpy); UNIT_TEST(TestPrefixSuffix); -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING UNIT_TEST(TestCharRef); -#endif +#endif UNIT_TEST(TestBack); UNIT_TEST(TestFront) UNIT_TEST(TestDecodingMethods); @@ -912,9 +912,9 @@ public: UNIT_TEST_SUITE(TUtf32StringTest); UNIT_TEST(TestConstructors); UNIT_TEST(TestReplace); -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING UNIT_TEST(TestRefCount); -#endif +#endif UNIT_TEST(TestFind); UNIT_TEST(TestContains); UNIT_TEST(TestOperators); @@ -927,9 +927,9 @@ public: UNIT_TEST(TestCopy); UNIT_TEST(TestStrCpy); UNIT_TEST(TestPrefixSuffix); -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING UNIT_TEST(TestCharRef); -#endif +#endif UNIT_TEST(TestBack); UNIT_TEST(TestFront) UNIT_TEST(TestDecodingMethods); diff --git a/util/generic/string_ut.h b/util/generic/string_ut.h index 44bb10bdeb..1f5255d4fe 100644 --- a/util/generic/string_ut.h +++ b/util/generic/string_ut.h @@ -1,513 +1,513 @@ -#pragma once - +#pragma once + #include "string.h" #include <library/cpp/testing/unittest/registar.h> -#include <util/string/reverse.h> - -template <typename CharT, size_t N> -struct TCharBuffer { - CharT Data[N]; - //! copies characters from string to the internal buffer without any conversion - //! @param s a string that must contain only characters less than 0x7F - explicit TCharBuffer(const char* s) { - // copy all symbols including null terminated symbol - for (size_t i = 0; i < N; ++i) { - Data[i] = s[i]; - } - } - const CharT* GetData() const { - return Data; - } -}; - -template <> -struct TCharBuffer<char, 0> { - const char* Data; - //! stores pointer to string - explicit TCharBuffer(const char* s) - : Data(s) - { - } - const char* GetData() const { - return Data; - } -}; - -#define DECLARE_AND_RETURN_BUFFER(s) \ - static TCharBuffer<CharT, sizeof(s)> buf(s); \ - return buf.GetData(); - -//! @attention this class can process characters less than 0x7F only (the low half of ASCII table) -template <typename CharT> -struct TTestData { - // words - const CharT* str1() { - DECLARE_AND_RETURN_BUFFER("str1"); - } - const CharT* str2() { - DECLARE_AND_RETURN_BUFFER("str2"); - } - const CharT* str__________________________________________________1() { - DECLARE_AND_RETURN_BUFFER("str 1"); - } - const CharT* str__________________________________________________2() { - DECLARE_AND_RETURN_BUFFER("str 2"); - } - const CharT* one() { - DECLARE_AND_RETURN_BUFFER("one"); - } - const CharT* two() { - DECLARE_AND_RETURN_BUFFER("two"); - } - const CharT* three() { - DECLARE_AND_RETURN_BUFFER("three"); - } - const CharT* thrii() { - DECLARE_AND_RETURN_BUFFER("thrii"); - } - const CharT* four() { - DECLARE_AND_RETURN_BUFFER("four"); - } - const CharT* enotw_() { - DECLARE_AND_RETURN_BUFFER("enotw "); - } - const CharT* foo() { - DECLARE_AND_RETURN_BUFFER("foo"); - } - const CharT* abcdef() { - DECLARE_AND_RETURN_BUFFER("abcdef"); - } - const CharT* abcdefg() { - DECLARE_AND_RETURN_BUFFER("abcdefg"); - } - const CharT* aba() { - DECLARE_AND_RETURN_BUFFER("aba"); - } - const CharT* hr() { - DECLARE_AND_RETURN_BUFFER("hr"); - } - const CharT* hrt() { - DECLARE_AND_RETURN_BUFFER("hrt"); - } - const CharT* thr() { - DECLARE_AND_RETURN_BUFFER("thr"); - } - const CharT* tw() { - DECLARE_AND_RETURN_BUFFER("tw"); - } - const CharT* ow() { - DECLARE_AND_RETURN_BUFFER("ow"); - } - const CharT* opq() { - DECLARE_AND_RETURN_BUFFER("opq"); - } - const CharT* xyz() { - DECLARE_AND_RETURN_BUFFER("xyz"); - } - const CharT* abc() { - DECLARE_AND_RETURN_BUFFER("abc"); - } - const CharT* abcd() { - DECLARE_AND_RETURN_BUFFER("abcd"); - } - const CharT* abcde() { - DECLARE_AND_RETURN_BUFFER("abcde"); - } - const CharT* abcc() { - DECLARE_AND_RETURN_BUFFER("abcc"); - } - const CharT* abce() { - DECLARE_AND_RETURN_BUFFER("abce"); - } - const CharT* qwe() { - DECLARE_AND_RETURN_BUFFER("qwe"); - } - const CharT* cd() { - DECLARE_AND_RETURN_BUFFER("cd"); - } - const CharT* cde() { - DECLARE_AND_RETURN_BUFFER("cde"); - } - const CharT* cdef() { - DECLARE_AND_RETURN_BUFFER("cdef"); - } - const CharT* cdefgh() { - DECLARE_AND_RETURN_BUFFER("cdefgh"); - } - const CharT* ehortw_() { - DECLARE_AND_RETURN_BUFFER("ehortw "); - } - const CharT* fg() { - DECLARE_AND_RETURN_BUFFER("fg"); - } - const CharT* abcdefgh() { - DECLARE_AND_RETURN_BUFFER("abcdefgh"); - } - - // phrases - const CharT* Hello_World() { - DECLARE_AND_RETURN_BUFFER("Hello World"); - } - const CharT* This_is_test_string_for_string_calls() { - DECLARE_AND_RETURN_BUFFER("This is test string for string calls"); - } - const CharT* This_is_teis_test_string_st_string_for_string_calls() { - DECLARE_AND_RETURN_BUFFER("This is teis test string st string for string calls"); - } - const CharT* This_is_test_stis_test_string_for_stringring_for_string_calls() { - DECLARE_AND_RETURN_BUFFER("This is test stis test string for stringring for string calls"); - } - const CharT* allsThis_is_test_string_for_string_calls() { - DECLARE_AND_RETURN_BUFFER("allsThis is test string for string calls"); - } - const CharT* ng_for_string_callsThis_is_test_string_for_string_calls() { - DECLARE_AND_RETURN_BUFFER("ng for string callsThis is test string for string calls"); - } - const CharT* one_two_three_one_two_three() { - DECLARE_AND_RETURN_BUFFER("one two three one two three"); - } - const CharT* test_string_for_assign() { - DECLARE_AND_RETURN_BUFFER("test string for assign"); - } - const CharT* other_test_string() { - DECLARE_AND_RETURN_BUFFER("other test string"); - } - const CharT* This_This_is_tefor_string_calls() { - DECLARE_AND_RETURN_BUFFER("This This is tefor string calls"); - } - const CharT* This_This_is_test_string_for_string_calls() { - DECLARE_AND_RETURN_BUFFER("This This is test string for string calls"); - } - - const CharT* _0123456x() { - DECLARE_AND_RETURN_BUFFER("0123456x"); - } - const CharT* _0123456xy() { - DECLARE_AND_RETURN_BUFFER("0123456xy"); - } - const CharT* _0123456xyz() { - DECLARE_AND_RETURN_BUFFER("0123456xyz"); - } - const CharT* _0123456xyzZ() { - DECLARE_AND_RETURN_BUFFER("0123456xyzZ"); - } - const CharT* _0123456xyzZ0() { - DECLARE_AND_RETURN_BUFFER("0123456xyzZ0"); - } - const CharT* abc0123456xyz() { - DECLARE_AND_RETURN_BUFFER("abc0123456xyz"); - } - const CharT* BCabc0123456xyz() { - DECLARE_AND_RETURN_BUFFER("BCabc0123456xyz"); - } - const CharT* qweBCabc0123456xyz() { - DECLARE_AND_RETURN_BUFFER("qweBCabc0123456xyz"); - } - const CharT* _1qweBCabc0123456xyz() { - DECLARE_AND_RETURN_BUFFER("1qweBCabc0123456xyz"); - } - const CharT* _01abc23456() { - DECLARE_AND_RETURN_BUFFER("01abc23456"); - } - const CharT* _01ABCabc23456() { - DECLARE_AND_RETURN_BUFFER("01ABCabc23456"); - } - const CharT* ABC() { - DECLARE_AND_RETURN_BUFFER("ABC"); - } - const CharT* ABCD() { - DECLARE_AND_RETURN_BUFFER("ABCD"); - } - const CharT* QWE() { - DECLARE_AND_RETURN_BUFFER("QWE"); - } - const CharT* XYZ() { - DECLARE_AND_RETURN_BUFFER("XYZ"); - } - const CharT* W01ABCabc23456() { - DECLARE_AND_RETURN_BUFFER("W01ABCabc23456"); - } - const CharT* abcd456() { - DECLARE_AND_RETURN_BUFFER("abcd456"); - } - const CharT* abcdABCD() { - DECLARE_AND_RETURN_BUFFER("abcdABCD"); - } - const CharT* abcdABC123() { - DECLARE_AND_RETURN_BUFFER("abcdABC123"); - } - const CharT* z123z123() { - DECLARE_AND_RETURN_BUFFER("z123z123"); - } - const CharT* ASDF1234QWER() { - DECLARE_AND_RETURN_BUFFER("ASDF1234QWER"); - } - const CharT* asdf1234qwer() { - DECLARE_AND_RETURN_BUFFER("asdf1234qwer"); - } - const CharT* asDF1234qWEr() { - DECLARE_AND_RETURN_BUFFER("asDF1234qWEr"); - } - const CharT* AsDF1234qWEr() { - DECLARE_AND_RETURN_BUFFER("AsDF1234qWEr"); - } - const CharT* Asdf1234qwer() { - DECLARE_AND_RETURN_BUFFER("Asdf1234qwer"); - } - const CharT* Asdf1234qwerWWWW() { - DECLARE_AND_RETURN_BUFFER("Asdf1234qwerWWWW"); - } - const CharT* Asdf() { - DECLARE_AND_RETURN_BUFFER("Asdf"); - } - const CharT* orig() { - DECLARE_AND_RETURN_BUFFER("orig"); - } - const CharT* fdfdsfds() { - DECLARE_AND_RETURN_BUFFER("fdfdsfds"); - } - - // numbers - const CharT* _0() { - DECLARE_AND_RETURN_BUFFER("0"); - } - const CharT* _00() { - DECLARE_AND_RETURN_BUFFER("00"); - } - const CharT* _0000000000() { - DECLARE_AND_RETURN_BUFFER("0000000000"); - } - const CharT* _00000() { - DECLARE_AND_RETURN_BUFFER("00000"); - } - const CharT* _0123() { - DECLARE_AND_RETURN_BUFFER("0123"); - } - const CharT* _01230123() { - DECLARE_AND_RETURN_BUFFER("01230123"); - } - const CharT* _01234() { - DECLARE_AND_RETURN_BUFFER("01234"); - } - const CharT* _0123401234() { - DECLARE_AND_RETURN_BUFFER("0123401234"); - } - const CharT* _012345() { - DECLARE_AND_RETURN_BUFFER("012345"); - } - const CharT* _0123456() { - DECLARE_AND_RETURN_BUFFER("0123456"); - } - const CharT* _1() { - DECLARE_AND_RETURN_BUFFER("1"); - } - const CharT* _11() { - DECLARE_AND_RETURN_BUFFER("11"); - } - const CharT* _1100000() { - DECLARE_AND_RETURN_BUFFER("1100000"); - } - const CharT* _110000034() { - DECLARE_AND_RETURN_BUFFER("110000034"); - } - const CharT* _12() { - DECLARE_AND_RETURN_BUFFER("12"); - } - const CharT* _123() { - DECLARE_AND_RETURN_BUFFER("123"); - } - const CharT* _1233321() { - DECLARE_AND_RETURN_BUFFER("1233321"); - } - const CharT* _1221() { - DECLARE_AND_RETURN_BUFFER("1221"); - } - const CharT* _1234123456() { - DECLARE_AND_RETURN_BUFFER("1234123456"); - } - const CharT* _12334444321() { - DECLARE_AND_RETURN_BUFFER("12334444321"); - } - const CharT* _123344544321() { - DECLARE_AND_RETURN_BUFFER("123344544321"); - } - const CharT* _1234567890123456789012345678901234567890() { - DECLARE_AND_RETURN_BUFFER("1234567890123456789012345678901234567890"); - } - const CharT* _1234() { - DECLARE_AND_RETURN_BUFFER("1234"); - } - const CharT* _12345() { - DECLARE_AND_RETURN_BUFFER("12345"); - } - const CharT* _123456() { - DECLARE_AND_RETURN_BUFFER("123456"); - } - const CharT* _1234567() { - DECLARE_AND_RETURN_BUFFER("1234567"); - } - const CharT* _1234561234() { - DECLARE_AND_RETURN_BUFFER("1234561234"); - } - const CharT* _12356() { - DECLARE_AND_RETURN_BUFFER("12356"); - } - const CharT* _1345656() { - DECLARE_AND_RETURN_BUFFER("1345656"); - } - const CharT* _15656() { - DECLARE_AND_RETURN_BUFFER("15656"); - } - const CharT* _17856() { - DECLARE_AND_RETURN_BUFFER("17856"); - } - const CharT* _1783456() { - DECLARE_AND_RETURN_BUFFER("1783456"); - } - const CharT* _2() { - DECLARE_AND_RETURN_BUFFER("2"); - } - const CharT* _2123456() { - DECLARE_AND_RETURN_BUFFER("2123456"); - } - const CharT* _23() { - DECLARE_AND_RETURN_BUFFER("23"); - } - const CharT* _2345() { - DECLARE_AND_RETURN_BUFFER("2345"); - } - const CharT* _3() { - DECLARE_AND_RETURN_BUFFER("3"); - } - const CharT* _345() { - DECLARE_AND_RETURN_BUFFER("345"); - } - const CharT* _3456() { - DECLARE_AND_RETURN_BUFFER("3456"); - } - const CharT* _333333() { - DECLARE_AND_RETURN_BUFFER("333333"); - } - const CharT* _389() { - DECLARE_AND_RETURN_BUFFER("389"); - } - const CharT* _4294967295() { - DECLARE_AND_RETURN_BUFFER("4294967295"); - } - const CharT* _4444() { - DECLARE_AND_RETURN_BUFFER("4444"); - } - const CharT* _5() { - DECLARE_AND_RETURN_BUFFER("5"); - } - const CharT* _6() { - DECLARE_AND_RETURN_BUFFER("6"); - } - const CharT* _6543210() { - DECLARE_AND_RETURN_BUFFER("6543210"); - } - const CharT* _7() { - DECLARE_AND_RETURN_BUFFER("7"); - } - const CharT* _78() { - DECLARE_AND_RETURN_BUFFER("78"); - } - const CharT* _2004_01_01() { - DECLARE_AND_RETURN_BUFFER("2004-01-01"); - } - const CharT* _1234562004_01_01() { - DECLARE_AND_RETURN_BUFFER("1234562004-01-01"); - } - const CharT* _0123456_12345() { - DECLARE_AND_RETURN_BUFFER("0123456_12345"); - } - - // letters - const CharT* a() { - DECLARE_AND_RETURN_BUFFER("a"); - } - const CharT* b() { - DECLARE_AND_RETURN_BUFFER("b"); - } - const CharT* c() { - DECLARE_AND_RETURN_BUFFER("c"); - } - const CharT* d() { - DECLARE_AND_RETURN_BUFFER("d"); - } - const CharT* e() { - DECLARE_AND_RETURN_BUFFER("e"); - } - const CharT* f() { - DECLARE_AND_RETURN_BUFFER("f"); - } - const CharT* h() { - DECLARE_AND_RETURN_BUFFER("h"); - } - const CharT* o() { - DECLARE_AND_RETURN_BUFFER("o"); - } - const CharT* p() { - DECLARE_AND_RETURN_BUFFER("p"); - } - const CharT* q() { - DECLARE_AND_RETURN_BUFFER("q"); - } - const CharT* r() { - DECLARE_AND_RETURN_BUFFER("r"); - } - const CharT* s() { - DECLARE_AND_RETURN_BUFFER("s"); - } - const CharT* t() { - DECLARE_AND_RETURN_BUFFER("t"); - } - const CharT* w() { - DECLARE_AND_RETURN_BUFFER("w"); - } - const CharT* x() { - DECLARE_AND_RETURN_BUFFER("x"); - } - const CharT* y() { - DECLARE_AND_RETURN_BUFFER("y"); - } - const CharT* z() { - DECLARE_AND_RETURN_BUFFER("z"); - } - const CharT* H() { - DECLARE_AND_RETURN_BUFFER("H"); - } - const CharT* I() { - DECLARE_AND_RETURN_BUFFER("I"); - } - const CharT* W() { - DECLARE_AND_RETURN_BUFFER("W"); - } - - const CharT* Space() { - DECLARE_AND_RETURN_BUFFER(" "); - } - const CharT* Empty() { - DECLARE_AND_RETURN_BUFFER(""); - } - - size_t HashOf_0123456() { - return 0; - } -}; - -template <> -size_t TTestData<char>::HashOf_0123456() { - return 1229863857ul; -} - -template <> -size_t TTestData<wchar16>::HashOf_0123456() { - return 2775195331ul; -} - +#include <util/string/reverse.h> + +template <typename CharT, size_t N> +struct TCharBuffer { + CharT Data[N]; + //! copies characters from string to the internal buffer without any conversion + //! @param s a string that must contain only characters less than 0x7F + explicit TCharBuffer(const char* s) { + // copy all symbols including null terminated symbol + for (size_t i = 0; i < N; ++i) { + Data[i] = s[i]; + } + } + const CharT* GetData() const { + return Data; + } +}; + +template <> +struct TCharBuffer<char, 0> { + const char* Data; + //! stores pointer to string + explicit TCharBuffer(const char* s) + : Data(s) + { + } + const char* GetData() const { + return Data; + } +}; + +#define DECLARE_AND_RETURN_BUFFER(s) \ + static TCharBuffer<CharT, sizeof(s)> buf(s); \ + return buf.GetData(); + +//! @attention this class can process characters less than 0x7F only (the low half of ASCII table) +template <typename CharT> +struct TTestData { + // words + const CharT* str1() { + DECLARE_AND_RETURN_BUFFER("str1"); + } + const CharT* str2() { + DECLARE_AND_RETURN_BUFFER("str2"); + } + const CharT* str__________________________________________________1() { + DECLARE_AND_RETURN_BUFFER("str 1"); + } + const CharT* str__________________________________________________2() { + DECLARE_AND_RETURN_BUFFER("str 2"); + } + const CharT* one() { + DECLARE_AND_RETURN_BUFFER("one"); + } + const CharT* two() { + DECLARE_AND_RETURN_BUFFER("two"); + } + const CharT* three() { + DECLARE_AND_RETURN_BUFFER("three"); + } + const CharT* thrii() { + DECLARE_AND_RETURN_BUFFER("thrii"); + } + const CharT* four() { + DECLARE_AND_RETURN_BUFFER("four"); + } + const CharT* enotw_() { + DECLARE_AND_RETURN_BUFFER("enotw "); + } + const CharT* foo() { + DECLARE_AND_RETURN_BUFFER("foo"); + } + const CharT* abcdef() { + DECLARE_AND_RETURN_BUFFER("abcdef"); + } + const CharT* abcdefg() { + DECLARE_AND_RETURN_BUFFER("abcdefg"); + } + const CharT* aba() { + DECLARE_AND_RETURN_BUFFER("aba"); + } + const CharT* hr() { + DECLARE_AND_RETURN_BUFFER("hr"); + } + const CharT* hrt() { + DECLARE_AND_RETURN_BUFFER("hrt"); + } + const CharT* thr() { + DECLARE_AND_RETURN_BUFFER("thr"); + } + const CharT* tw() { + DECLARE_AND_RETURN_BUFFER("tw"); + } + const CharT* ow() { + DECLARE_AND_RETURN_BUFFER("ow"); + } + const CharT* opq() { + DECLARE_AND_RETURN_BUFFER("opq"); + } + const CharT* xyz() { + DECLARE_AND_RETURN_BUFFER("xyz"); + } + const CharT* abc() { + DECLARE_AND_RETURN_BUFFER("abc"); + } + const CharT* abcd() { + DECLARE_AND_RETURN_BUFFER("abcd"); + } + const CharT* abcde() { + DECLARE_AND_RETURN_BUFFER("abcde"); + } + const CharT* abcc() { + DECLARE_AND_RETURN_BUFFER("abcc"); + } + const CharT* abce() { + DECLARE_AND_RETURN_BUFFER("abce"); + } + const CharT* qwe() { + DECLARE_AND_RETURN_BUFFER("qwe"); + } + const CharT* cd() { + DECLARE_AND_RETURN_BUFFER("cd"); + } + const CharT* cde() { + DECLARE_AND_RETURN_BUFFER("cde"); + } + const CharT* cdef() { + DECLARE_AND_RETURN_BUFFER("cdef"); + } + const CharT* cdefgh() { + DECLARE_AND_RETURN_BUFFER("cdefgh"); + } + const CharT* ehortw_() { + DECLARE_AND_RETURN_BUFFER("ehortw "); + } + const CharT* fg() { + DECLARE_AND_RETURN_BUFFER("fg"); + } + const CharT* abcdefgh() { + DECLARE_AND_RETURN_BUFFER("abcdefgh"); + } + + // phrases + const CharT* Hello_World() { + DECLARE_AND_RETURN_BUFFER("Hello World"); + } + const CharT* This_is_test_string_for_string_calls() { + DECLARE_AND_RETURN_BUFFER("This is test string for string calls"); + } + const CharT* This_is_teis_test_string_st_string_for_string_calls() { + DECLARE_AND_RETURN_BUFFER("This is teis test string st string for string calls"); + } + const CharT* This_is_test_stis_test_string_for_stringring_for_string_calls() { + DECLARE_AND_RETURN_BUFFER("This is test stis test string for stringring for string calls"); + } + const CharT* allsThis_is_test_string_for_string_calls() { + DECLARE_AND_RETURN_BUFFER("allsThis is test string for string calls"); + } + const CharT* ng_for_string_callsThis_is_test_string_for_string_calls() { + DECLARE_AND_RETURN_BUFFER("ng for string callsThis is test string for string calls"); + } + const CharT* one_two_three_one_two_three() { + DECLARE_AND_RETURN_BUFFER("one two three one two three"); + } + const CharT* test_string_for_assign() { + DECLARE_AND_RETURN_BUFFER("test string for assign"); + } + const CharT* other_test_string() { + DECLARE_AND_RETURN_BUFFER("other test string"); + } + const CharT* This_This_is_tefor_string_calls() { + DECLARE_AND_RETURN_BUFFER("This This is tefor string calls"); + } + const CharT* This_This_is_test_string_for_string_calls() { + DECLARE_AND_RETURN_BUFFER("This This is test string for string calls"); + } + + const CharT* _0123456x() { + DECLARE_AND_RETURN_BUFFER("0123456x"); + } + const CharT* _0123456xy() { + DECLARE_AND_RETURN_BUFFER("0123456xy"); + } + const CharT* _0123456xyz() { + DECLARE_AND_RETURN_BUFFER("0123456xyz"); + } + const CharT* _0123456xyzZ() { + DECLARE_AND_RETURN_BUFFER("0123456xyzZ"); + } + const CharT* _0123456xyzZ0() { + DECLARE_AND_RETURN_BUFFER("0123456xyzZ0"); + } + const CharT* abc0123456xyz() { + DECLARE_AND_RETURN_BUFFER("abc0123456xyz"); + } + const CharT* BCabc0123456xyz() { + DECLARE_AND_RETURN_BUFFER("BCabc0123456xyz"); + } + const CharT* qweBCabc0123456xyz() { + DECLARE_AND_RETURN_BUFFER("qweBCabc0123456xyz"); + } + const CharT* _1qweBCabc0123456xyz() { + DECLARE_AND_RETURN_BUFFER("1qweBCabc0123456xyz"); + } + const CharT* _01abc23456() { + DECLARE_AND_RETURN_BUFFER("01abc23456"); + } + const CharT* _01ABCabc23456() { + DECLARE_AND_RETURN_BUFFER("01ABCabc23456"); + } + const CharT* ABC() { + DECLARE_AND_RETURN_BUFFER("ABC"); + } + const CharT* ABCD() { + DECLARE_AND_RETURN_BUFFER("ABCD"); + } + const CharT* QWE() { + DECLARE_AND_RETURN_BUFFER("QWE"); + } + const CharT* XYZ() { + DECLARE_AND_RETURN_BUFFER("XYZ"); + } + const CharT* W01ABCabc23456() { + DECLARE_AND_RETURN_BUFFER("W01ABCabc23456"); + } + const CharT* abcd456() { + DECLARE_AND_RETURN_BUFFER("abcd456"); + } + const CharT* abcdABCD() { + DECLARE_AND_RETURN_BUFFER("abcdABCD"); + } + const CharT* abcdABC123() { + DECLARE_AND_RETURN_BUFFER("abcdABC123"); + } + const CharT* z123z123() { + DECLARE_AND_RETURN_BUFFER("z123z123"); + } + const CharT* ASDF1234QWER() { + DECLARE_AND_RETURN_BUFFER("ASDF1234QWER"); + } + const CharT* asdf1234qwer() { + DECLARE_AND_RETURN_BUFFER("asdf1234qwer"); + } + const CharT* asDF1234qWEr() { + DECLARE_AND_RETURN_BUFFER("asDF1234qWEr"); + } + const CharT* AsDF1234qWEr() { + DECLARE_AND_RETURN_BUFFER("AsDF1234qWEr"); + } + const CharT* Asdf1234qwer() { + DECLARE_AND_RETURN_BUFFER("Asdf1234qwer"); + } + const CharT* Asdf1234qwerWWWW() { + DECLARE_AND_RETURN_BUFFER("Asdf1234qwerWWWW"); + } + const CharT* Asdf() { + DECLARE_AND_RETURN_BUFFER("Asdf"); + } + const CharT* orig() { + DECLARE_AND_RETURN_BUFFER("orig"); + } + const CharT* fdfdsfds() { + DECLARE_AND_RETURN_BUFFER("fdfdsfds"); + } + + // numbers + const CharT* _0() { + DECLARE_AND_RETURN_BUFFER("0"); + } + const CharT* _00() { + DECLARE_AND_RETURN_BUFFER("00"); + } + const CharT* _0000000000() { + DECLARE_AND_RETURN_BUFFER("0000000000"); + } + const CharT* _00000() { + DECLARE_AND_RETURN_BUFFER("00000"); + } + const CharT* _0123() { + DECLARE_AND_RETURN_BUFFER("0123"); + } + const CharT* _01230123() { + DECLARE_AND_RETURN_BUFFER("01230123"); + } + const CharT* _01234() { + DECLARE_AND_RETURN_BUFFER("01234"); + } + const CharT* _0123401234() { + DECLARE_AND_RETURN_BUFFER("0123401234"); + } + const CharT* _012345() { + DECLARE_AND_RETURN_BUFFER("012345"); + } + const CharT* _0123456() { + DECLARE_AND_RETURN_BUFFER("0123456"); + } + const CharT* _1() { + DECLARE_AND_RETURN_BUFFER("1"); + } + const CharT* _11() { + DECLARE_AND_RETURN_BUFFER("11"); + } + const CharT* _1100000() { + DECLARE_AND_RETURN_BUFFER("1100000"); + } + const CharT* _110000034() { + DECLARE_AND_RETURN_BUFFER("110000034"); + } + const CharT* _12() { + DECLARE_AND_RETURN_BUFFER("12"); + } + const CharT* _123() { + DECLARE_AND_RETURN_BUFFER("123"); + } + const CharT* _1233321() { + DECLARE_AND_RETURN_BUFFER("1233321"); + } + const CharT* _1221() { + DECLARE_AND_RETURN_BUFFER("1221"); + } + const CharT* _1234123456() { + DECLARE_AND_RETURN_BUFFER("1234123456"); + } + const CharT* _12334444321() { + DECLARE_AND_RETURN_BUFFER("12334444321"); + } + const CharT* _123344544321() { + DECLARE_AND_RETURN_BUFFER("123344544321"); + } + const CharT* _1234567890123456789012345678901234567890() { + DECLARE_AND_RETURN_BUFFER("1234567890123456789012345678901234567890"); + } + const CharT* _1234() { + DECLARE_AND_RETURN_BUFFER("1234"); + } + const CharT* _12345() { + DECLARE_AND_RETURN_BUFFER("12345"); + } + const CharT* _123456() { + DECLARE_AND_RETURN_BUFFER("123456"); + } + const CharT* _1234567() { + DECLARE_AND_RETURN_BUFFER("1234567"); + } + const CharT* _1234561234() { + DECLARE_AND_RETURN_BUFFER("1234561234"); + } + const CharT* _12356() { + DECLARE_AND_RETURN_BUFFER("12356"); + } + const CharT* _1345656() { + DECLARE_AND_RETURN_BUFFER("1345656"); + } + const CharT* _15656() { + DECLARE_AND_RETURN_BUFFER("15656"); + } + const CharT* _17856() { + DECLARE_AND_RETURN_BUFFER("17856"); + } + const CharT* _1783456() { + DECLARE_AND_RETURN_BUFFER("1783456"); + } + const CharT* _2() { + DECLARE_AND_RETURN_BUFFER("2"); + } + const CharT* _2123456() { + DECLARE_AND_RETURN_BUFFER("2123456"); + } + const CharT* _23() { + DECLARE_AND_RETURN_BUFFER("23"); + } + const CharT* _2345() { + DECLARE_AND_RETURN_BUFFER("2345"); + } + const CharT* _3() { + DECLARE_AND_RETURN_BUFFER("3"); + } + const CharT* _345() { + DECLARE_AND_RETURN_BUFFER("345"); + } + const CharT* _3456() { + DECLARE_AND_RETURN_BUFFER("3456"); + } + const CharT* _333333() { + DECLARE_AND_RETURN_BUFFER("333333"); + } + const CharT* _389() { + DECLARE_AND_RETURN_BUFFER("389"); + } + const CharT* _4294967295() { + DECLARE_AND_RETURN_BUFFER("4294967295"); + } + const CharT* _4444() { + DECLARE_AND_RETURN_BUFFER("4444"); + } + const CharT* _5() { + DECLARE_AND_RETURN_BUFFER("5"); + } + const CharT* _6() { + DECLARE_AND_RETURN_BUFFER("6"); + } + const CharT* _6543210() { + DECLARE_AND_RETURN_BUFFER("6543210"); + } + const CharT* _7() { + DECLARE_AND_RETURN_BUFFER("7"); + } + const CharT* _78() { + DECLARE_AND_RETURN_BUFFER("78"); + } + const CharT* _2004_01_01() { + DECLARE_AND_RETURN_BUFFER("2004-01-01"); + } + const CharT* _1234562004_01_01() { + DECLARE_AND_RETURN_BUFFER("1234562004-01-01"); + } + const CharT* _0123456_12345() { + DECLARE_AND_RETURN_BUFFER("0123456_12345"); + } + + // letters + const CharT* a() { + DECLARE_AND_RETURN_BUFFER("a"); + } + const CharT* b() { + DECLARE_AND_RETURN_BUFFER("b"); + } + const CharT* c() { + DECLARE_AND_RETURN_BUFFER("c"); + } + const CharT* d() { + DECLARE_AND_RETURN_BUFFER("d"); + } + const CharT* e() { + DECLARE_AND_RETURN_BUFFER("e"); + } + const CharT* f() { + DECLARE_AND_RETURN_BUFFER("f"); + } + const CharT* h() { + DECLARE_AND_RETURN_BUFFER("h"); + } + const CharT* o() { + DECLARE_AND_RETURN_BUFFER("o"); + } + const CharT* p() { + DECLARE_AND_RETURN_BUFFER("p"); + } + const CharT* q() { + DECLARE_AND_RETURN_BUFFER("q"); + } + const CharT* r() { + DECLARE_AND_RETURN_BUFFER("r"); + } + const CharT* s() { + DECLARE_AND_RETURN_BUFFER("s"); + } + const CharT* t() { + DECLARE_AND_RETURN_BUFFER("t"); + } + const CharT* w() { + DECLARE_AND_RETURN_BUFFER("w"); + } + const CharT* x() { + DECLARE_AND_RETURN_BUFFER("x"); + } + const CharT* y() { + DECLARE_AND_RETURN_BUFFER("y"); + } + const CharT* z() { + DECLARE_AND_RETURN_BUFFER("z"); + } + const CharT* H() { + DECLARE_AND_RETURN_BUFFER("H"); + } + const CharT* I() { + DECLARE_AND_RETURN_BUFFER("I"); + } + const CharT* W() { + DECLARE_AND_RETURN_BUFFER("W"); + } + + const CharT* Space() { + DECLARE_AND_RETURN_BUFFER(" "); + } + const CharT* Empty() { + DECLARE_AND_RETURN_BUFFER(""); + } + + size_t HashOf_0123456() { + return 0; + } +}; + +template <> +size_t TTestData<char>::HashOf_0123456() { + return 1229863857ul; +} + +template <> +size_t TTestData<wchar16>::HashOf_0123456() { + return 2775195331ul; +} + template <class TStringType, typename TTestData> class TStringTestImpl { protected: @@ -518,7 +518,7 @@ protected: public: void TestMaxSize() { - const size_t badMaxVal = TStringType{}.max_size() + 1; + const size_t badMaxVal = TStringType{}.max_size() + 1; TStringType s; UNIT_CHECK_GENERATED_EXCEPTION(s.reserve(badMaxVal), std::length_error); @@ -541,10 +541,10 @@ public: UNIT_ASSERT_VALUES_EQUAL(fromChar.size(), 1u); UNIT_ASSERT_VALUES_EQUAL(fromChar[0], char_type('a')); -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING TStringType s3 = TStringType::Uninitialized(10); UNIT_ASSERT(s3.size() == 10); -#endif +#endif TStringType s4(Data._0123456(), 1, 3); UNIT_ASSERT(s4 == Data._123()); @@ -556,9 +556,9 @@ public: UNIT_ASSERT(s6 == Data._0123456()); TStringType s7(s6); UNIT_ASSERT(s7 == s6); -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING UNIT_ASSERT(s7.c_str() == s6.c_str()); -#endif +#endif TStringType s8(s7, 1, 3); UNIT_ASSERT(s8 == Data._123()); @@ -568,7 +568,7 @@ public: TStringType s10(Reserve(100)); UNIT_ASSERT(s10.empty()); - UNIT_ASSERT(s10.capacity() >= 100); + UNIT_ASSERT(s10.capacity() >= 100); } void TestReplace() { @@ -579,11 +579,11 @@ public: s.append(Data.x()); UNIT_ASSERT(s == Data._0123456x()); -#ifdef TSTRING_IS_STD_STRING - s.append(Data.xyz() + 1, 1); -#else +#ifdef TSTRING_IS_STD_STRING + s.append(Data.xyz() + 1, 1); +#else s.append(Data.xyz(), 1, 1); -#endif +#endif UNIT_ASSERT(s == Data._0123456xy()); s.append(TStringType(Data.z())); @@ -650,7 +650,7 @@ public: UNIT_ASSERT(s[s.size()] == 0); } -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING void TestRefCount() { using TStr = TStringType; @@ -672,7 +672,7 @@ public: UNIT_ASSERT_EQUAL(s2.RefCount() == 1, true); UNIT_ASSERT_EQUAL(s1.c_str() == s2.c_str(), false); } -#endif +#endif // Find family @@ -797,11 +797,11 @@ public: UNIT_ASSERT(s > Data.abc0123456xyz()); UNIT_ASSERT(s == Data.abcd()); - using TCIStringBuf = TBasicStringBuf<char_type, traits_type>; - - UNIT_ASSERT(s > TCIStringBuf(Data.abc0123456xyz())); - UNIT_ASSERT(TCIStringBuf(Data.abc0123456xyz()) < s); - UNIT_ASSERT(s == TCIStringBuf(Data.abcd())); + using TCIStringBuf = TBasicStringBuf<char_type, traits_type>; + + UNIT_ASSERT(s > TCIStringBuf(Data.abc0123456xyz())); + UNIT_ASSERT(TCIStringBuf(Data.abc0123456xyz()) < s); + UNIT_ASSERT(s == TCIStringBuf(Data.abcd())); } void TestMulOperators() { @@ -836,7 +836,7 @@ public: UNIT_ASSERT(s2 == s); // reverse() - ReverseInPlace(s2); + ReverseInPlace(s2); UNIT_ASSERT(s2 == Data._6543210()); // to_upper() @@ -894,7 +894,7 @@ public: // hash() TStringType sS = s2; // type 'TStringType' is used as is - ComputeHash(sS); /*size_t hash_val = sS.hash(); + ComputeHash(sS); /*size_t hash_val = sS.hash(); try { //UNIT_ASSERT(hash_val == Data.HashOf_0123456()); @@ -998,7 +998,7 @@ public: UNIT_ASSERT_EQUAL(str.EndsWith(emptyStr), true); } -#ifndef TSTRING_IS_STD_STRING +#ifndef TSTRING_IS_STD_STRING void TestCharRef() { const char_type abc[] = {'a', 'b', 'c', 0}; const char_type bbc[] = {'b', 'b', 'c', 0}; @@ -1045,7 +1045,7 @@ public: UNIT_ASSERT_VALUES_EQUAL(s1, red_eared); } } -#endif +#endif void TestBack() { const char_type chars[] = {'f', 'o', 'o', 0}; diff --git a/util/generic/variant.h b/util/generic/variant.h index 749fc75090..080f0a6e7e 100644 --- a/util/generic/variant.h +++ b/util/generic/variant.h @@ -1,23 +1,23 @@ #pragma once -#include "hash.h" +#include "hash.h" -#include <variant> +#include <variant> template <class... Ts> -struct THash<std::variant<Ts...>> { +struct THash<std::variant<Ts...>> { public: - size_t operator()(const std::variant<Ts...>& v) const noexcept { - return CombineHashes( - IntHash(v.index()), - v.valueless_by_exception() ? 0 : std::visit([](const auto& value) { return ComputeHash(value); }, v)); + size_t operator()(const std::variant<Ts...>& v) const noexcept { + return CombineHashes( + IntHash(v.index()), + v.valueless_by_exception() ? 0 : std::visit([](const auto& value) { return ComputeHash(value); }, v)); } }; template <> -struct THash<std::monostate> { +struct THash<std::monostate> { public: - constexpr size_t operator()(std::monostate) const noexcept { + constexpr size_t operator()(std::monostate) const noexcept { return 1; } }; |