aboutsummaryrefslogtreecommitdiffstats
path: root/util/generic
diff options
context:
space:
mode:
authornga <nga@yandex-team.ru>2022-02-10 16:48:09 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:48:09 +0300
commitc2a1af049e9deca890e9923abe64fe6c59060348 (patch)
treeb222e5ac2e2e98872661c51ccceee5da0d291e13 /util/generic
parent1f553f46fb4f3c5eec631352cdd900a0709016af (diff)
downloadydb-c2a1af049e9deca890e9923abe64fe6c59060348.tar.gz
Restoring authorship annotation for <nga@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util/generic')
-rw-r--r--util/generic/bitops.h2
-rw-r--r--util/generic/buffer.h8
-rw-r--r--util/generic/cast.h38
-rw-r--r--util/generic/maybe.h44
-rw-r--r--util/generic/maybe_ut.cpp62
-rw-r--r--util/generic/object_counter.h28
-rw-r--r--util/generic/ptr.h6
-rw-r--r--util/generic/refcount.h8
-rw-r--r--util/generic/string.h2
-rw-r--r--util/generic/typetraits_ut.cpp234
-rw-r--r--util/generic/vector_ut.cpp184
-rw-r--r--util/generic/ylimits.h6
-rw-r--r--util/generic/ymath_ut.cpp18
13 files changed, 320 insertions, 320 deletions
diff --git a/util/generic/bitops.h b/util/generic/bitops.h
index fb12548d12..2db15fc59b 100644
--- a/util/generic/bitops.h
+++ b/util/generic/bitops.h
@@ -62,7 +62,7 @@ namespace NBitOps {
Y_ASSERT(value); // because __builtin_clz* have undefined result for zero.
return std::numeric_limits<unsigned int>::digits - __builtin_clz(value);
}
-
+
inline unsigned GetValueBitCountImpl(unsigned long value) noexcept {
Y_ASSERT(value); // because __builtin_clz* have undefined result for zero.
return std::numeric_limits<unsigned long>::digits - __builtin_clzl(value);
diff --git a/util/generic/buffer.h b/util/generic/buffer.h
index d3cbf95a01..9576467404 100644
--- a/util/generic/buffer.h
+++ b/util/generic/buffer.h
@@ -87,7 +87,7 @@ public:
inline explicit operator bool() const noexcept {
return Size();
}
-
+
inline size_t Avail() const noexcept {
return Len_ - Pos_;
}
@@ -123,9 +123,9 @@ public:
} else {
memmove(Data_ + pos, Data_ + end, Pos_ - end);
Pos_ -= count;
- }
+ }
}
-
+
inline void ChopHead(size_t count) {
Chop(0U, count);
}
@@ -136,7 +136,7 @@ public:
}
inline void Advance(size_t len) {
- Resize(Pos_ + len);
+ Resize(Pos_ + len);
}
inline void Reserve(size_t len) {
diff --git a/util/generic/cast.h b/util/generic/cast.h
index 1868a7a36b..0d4a41f385 100644
--- a/util/generic/cast.h
+++ b/util/generic/cast.h
@@ -10,37 +10,37 @@
#include <cstdlib>
-template <class T, class F>
-static inline T VerifyDynamicCast(F f) {
- if (!f) {
+template <class T, class F>
+static inline T VerifyDynamicCast(F f) {
+ if (!f) {
return nullptr;
- }
-
- T ret = dynamic_cast<T>(f);
-
+ }
+
+ T ret = dynamic_cast<T>(f);
+
Y_VERIFY(ret, "verify cast failed");
-
- return ret;
-}
-
+
+ return ret;
+}
+
#if !defined(NDEBUG)
#define USE_DEBUG_CHECKED_CAST
#endif
-namespace NPrivate {
- template <typename T, typename F>
- static T DynamicCast(F f) {
- return dynamic_cast<T>(f);
- }
-}
-
+namespace NPrivate {
+ template <typename T, typename F>
+ static T DynamicCast(F f) {
+ return dynamic_cast<T>(f);
+ }
+}
+
/*
* replacement for dynamic_cast(dynamic_cast in debug mode, else static_cast)
*/
template <class T, class F>
static inline T CheckedCast(F f) {
#if defined(USE_DEBUG_CHECKED_CAST)
- return VerifyDynamicCast<T>(f);
+ return VerifyDynamicCast<T>(f);
#else
/* Make sure F is polymorphic.
* Without this cast, CheckedCast with non-polymorphic F
diff --git a/util/generic/maybe.h b/util/generic/maybe.h
index b07de3b3b5..34d21aebcd 100644
--- a/util/generic/maybe.h
+++ b/util/generic/maybe.h
@@ -222,7 +222,7 @@ public:
}
~TMaybe() = default;
-
+
constexpr TMaybe& operator=(const TMaybe&) = default;
constexpr TMaybe& operator=(TMaybe&&) = default;
@@ -238,9 +238,9 @@ public:
} else {
Init(std::forward<U>(right));
}
- return *this;
- }
-
+ return *this;
+ }
+
template <class U>
std::enable_if_t<TCopyAssignable<U>::value,
TMaybe&>
@@ -289,16 +289,16 @@ public:
this->Defined_ = false;
Data()->~T();
}
- }
-
+ }
+
constexpr bool Defined() const noexcept {
return this->Defined_;
}
-
+
Y_PURE_FUNCTION constexpr bool Empty() const noexcept {
return !Defined();
- }
-
+ }
+
void CheckDefined() const {
if (Y_UNLIKELY(!Defined())) {
Policy::OnEmpty(typeid(TValueType));
@@ -314,17 +314,17 @@ public:
}
constexpr const T& GetRef() const& {
- CheckDefined();
+ CheckDefined();
return *Data();
- }
-
+ }
+
constexpr T& GetRef() & {
- CheckDefined();
+ CheckDefined();
return *Data();
- }
-
+ }
+
constexpr const T&& GetRef() const&& {
CheckDefined();
@@ -340,11 +340,11 @@ public:
constexpr const T& operator*() const& {
return GetRef();
}
-
+
constexpr T& operator*() & {
return GetRef();
- }
-
+ }
+
constexpr const T&& operator*() const&& {
return std::move(GetRef());
}
@@ -355,8 +355,8 @@ public:
constexpr const T* operator->() const {
return &GetRef();
- }
-
+ }
+
constexpr T* operator->() {
return &GetRef();
}
@@ -384,8 +384,8 @@ public:
constexpr explicit operator bool() const noexcept {
return Defined();
- }
-
+ }
+
void Save(IOutputStream* out) const {
const bool defined = Defined();
diff --git a/util/generic/maybe_ut.cpp b/util/generic/maybe_ut.cpp
index a9afc4661a..2c1a425c5e 100644
--- a/util/generic/maybe_ut.cpp
+++ b/util/generic/maybe_ut.cpp
@@ -2,24 +2,24 @@
#include <util/generic/vector.h>
#include <util/stream/str.h>
#include <library/cpp/testing/unittest/registar.h>
-
-#include "maybe.h"
-
-class TIncrementOnDestroy {
-private:
+
+#include "maybe.h"
+
+class TIncrementOnDestroy {
+private:
int* Ptr_;
-public:
+public:
TIncrementOnDestroy(int* ptr) noexcept
: Ptr_(ptr)
{
- }
+ }
~TIncrementOnDestroy() {
++*Ptr_;
}
-};
-
+};
+
Y_UNIT_TEST_SUITE(TMaybeTest) {
Y_UNIT_TEST(TestStatic) {
using T1 = TMaybe<int>;
@@ -56,35 +56,35 @@ Y_UNIT_TEST_SUITE(TMaybeTest) {
Y_UNIT_TEST(TTestConstructorDestructor) {
int a = 0;
int b = 0;
-
- TMaybe<TIncrementOnDestroy>();
+
+ TMaybe<TIncrementOnDestroy>();
UNIT_ASSERT_VALUES_EQUAL(a, b);
-
+
TMaybe<TIncrementOnDestroy>(TIncrementOnDestroy(&a));
b += 2;
UNIT_ASSERT_VALUES_EQUAL(a, b);
-
- {
+
+ {
TMaybe<TIncrementOnDestroy> m1 = TIncrementOnDestroy(&a);
b += 1;
UNIT_ASSERT_VALUES_EQUAL(a, b);
-
+
TMaybe<TIncrementOnDestroy> m2 = m1;
UNIT_ASSERT_VALUES_EQUAL(a, b);
-
+
TMaybe<TIncrementOnDestroy> m3;
m3 = m1;
UNIT_ASSERT_VALUES_EQUAL(a, b);
- }
-
+ }
+
b += 3;
UNIT_ASSERT_VALUES_EQUAL(a, b);
-
- {
+
+ {
TMaybe<TIncrementOnDestroy> m4 = TIncrementOnDestroy(&a);
b += 1;
UNIT_ASSERT_VALUES_EQUAL(a, b);
-
+
m4 = TIncrementOnDestroy(&a);
b += 1;
UNIT_ASSERT_VALUES_EQUAL(a, b);
@@ -95,9 +95,9 @@ Y_UNIT_TEST_SUITE(TMaybeTest) {
m4.Clear();
UNIT_ASSERT_VALUES_EQUAL(a, b);
- }
- }
-
+ }
+ }
+
Y_UNIT_TEST(TestAssignmentClear) {
TMaybe<int> m5;
UNIT_ASSERT(!m5.Defined());
@@ -105,24 +105,24 @@ Y_UNIT_TEST_SUITE(TMaybeTest) {
UNIT_ASSERT(m5 == TMaybe<int>());
UNIT_ASSERT(m5 == Nothing());
UNIT_ASSERT(m5 != TMaybe<int>(4));
-
+
m5 = 4;
-
+
UNIT_ASSERT(m5.Defined());
UNIT_ASSERT(!m5.Empty());
-
+
UNIT_ASSERT_VALUES_EQUAL(4, m5.GetRef());
UNIT_ASSERT(m5 == TMaybe<int>(4));
UNIT_ASSERT(m5 != TMaybe<int>(3));
UNIT_ASSERT(m5 != TMaybe<int>());
UNIT_ASSERT(m5 != Nothing());
-
+
m5 = TMaybe<int>(5);
UNIT_ASSERT(m5.Defined());
UNIT_ASSERT_VALUES_EQUAL(5, m5.GetRef());
UNIT_ASSERT(m5 == TMaybe<int>(5));
UNIT_ASSERT(m5 != TMaybe<int>(4));
-
+
m5 = TMaybe<int>();
UNIT_ASSERT(m5.Empty());
UNIT_ASSERT(m5 == TMaybe<int>());
@@ -139,7 +139,7 @@ Y_UNIT_TEST_SUITE(TMaybeTest) {
m5 = {};
UNIT_ASSERT(m5.Empty());
- }
+ }
Y_UNIT_TEST(TestInPlace) {
TMaybe<int> m;
@@ -1003,4 +1003,4 @@ Y_UNIT_TEST_SUITE(TMaybeTest) {
TMaybe<TStringBuf> v;
UNIT_ASSERT_EXCEPTION_CONTAINS(v.GetRef(), yexception, "StringBuf");
}
-}
+}
diff --git a/util/generic/object_counter.h b/util/generic/object_counter.h
index 71ec5d57c4..5257afa2e6 100644
--- a/util/generic/object_counter.h
+++ b/util/generic/object_counter.h
@@ -1,7 +1,7 @@
-#pragma once
-
-#include <util/system/atomic.h>
-
+#pragma once
+
+#include <util/system/atomic.h>
+
/**
* Simple thread-safe per-class counter that can be used to make sure you don't
* have any leaks in your code, or for statistical purposes.
@@ -16,13 +16,13 @@
* Cerr << "TMyClass instances in use: " << TMyClass::ObjectCount() << Endl;
* \endcode
*/
-template <class T>
-class TObjectCounter {
+template <class T>
+class TObjectCounter {
public:
inline TObjectCounter() noexcept {
AtomicIncrement(Count_);
}
-
+
inline TObjectCounter(const TObjectCounter& /*item*/) noexcept {
AtomicIncrement(Count_);
}
@@ -30,11 +30,11 @@ public:
inline ~TObjectCounter() {
AtomicDecrement(Count_);
}
-
+
static inline long ObjectCount() noexcept {
return AtomicGet(Count_);
}
-
+
/**
* Resets object count. Mainly for tests, as you don't want to do this in
* your code and then end up with negative counts.
@@ -44,10 +44,10 @@ public:
static inline long ResetObjectCount() noexcept {
return AtomicSwap(&Count_, 0);
}
-
+
private:
static TAtomic Count_;
-};
-
-template <class T>
-TAtomic TObjectCounter<T>::Count_ = 0;
+};
+
+template <class T>
+TAtomic TObjectCounter<T>::Count_ = 0;
diff --git a/util/generic/ptr.h b/util/generic/ptr.h
index 3b02d9c19f..19db0e3ec5 100644
--- a/util/generic/ptr.h
+++ b/util/generic/ptr.h
@@ -370,7 +370,7 @@ public:
Y_ASSERT(resultCount >= d);
(void)resultCount;
}
-
+
inline void Ref() noexcept {
auto resultCount = Counter_.Inc();
Y_ASSERT(resultCount != 0);
@@ -388,7 +388,7 @@ public:
inline void UnRef() noexcept {
UnRef(1);
}
-
+
inline TAtomicBase RefCount() const noexcept {
return Counter_.Val();
}
@@ -876,7 +876,7 @@ public:
inline void Drop() noexcept {
TSharedPtr().Swap(*this);
}
-
+
inline T* Get() const noexcept {
return T_;
}
diff --git a/util/generic/refcount.h b/util/generic/refcount.h
index c567cdfa3a..966e853b77 100644
--- a/util/generic/refcount.h
+++ b/util/generic/refcount.h
@@ -23,11 +23,11 @@ public:
Check();
return Counter_ += d;
}
-
+
inline TAtomicBase Inc() noexcept {
return Add(1);
}
-
+
inline TAtomicBase Sub(TAtomicBase d) noexcept {
Check();
return Counter_ -= d;
@@ -112,7 +112,7 @@ public:
inline TAtomicBase Add(TAtomicBase d) noexcept {
return AtomicAdd(Counter_, d);
}
-
+
inline TAtomicBase Inc() noexcept {
return Add(1);
}
@@ -120,7 +120,7 @@ public:
inline TAtomicBase Sub(TAtomicBase d) noexcept {
return AtomicSub(Counter_, d);
}
-
+
inline TAtomicBase Dec() noexcept {
return Sub(1);
}
diff --git a/util/generic/string.h b/util/generic/string.h
index f3e28037e6..8cd8aa6917 100644
--- a/util/generic/string.h
+++ b/util/generic/string.h
@@ -1133,7 +1133,7 @@ public:
extern TBasicString EscapeC(const TBasicString&);
return TBasicString() + '"' + EscapeC(*this) + '"';
- }
+ }
/**
* Modifies the case of the string, depending on the operation.
diff --git a/util/generic/typetraits_ut.cpp b/util/generic/typetraits_ut.cpp
index 59b6f2a9cf..e7571c75ec 100644
--- a/util/generic/typetraits_ut.cpp
+++ b/util/generic/typetraits_ut.cpp
@@ -5,17 +5,17 @@
#include <vector>
#include <tuple>
-namespace {
- enum ETestEnum {
- };
-
+namespace {
+ enum ETestEnum {
+ };
+
class TPodClass {
- };
-
+ };
+
class TNonPodClass {
TNonPodClass() {
}
- };
+ };
class TEmptyClass {
void operator()() const {
@@ -70,8 +70,8 @@ namespace {
public:
TEmptyClass Base;
};
-}
-
+}
+
#define ASSERT_SAME_TYPE(x, y) \
{ \
const bool x_ = std::is_same<x, y>::value; \
@@ -259,82 +259,82 @@ Y_UNIT_TEST_SUITE(TTypeTraitsTest) {
}
};
-namespace {
- template <typename T>
- struct TTypeTraitsExpected;
-
- template <>
- struct TTypeTraitsExpected<void> {
- enum { IsIntegral = false };
- enum { IsArithmetic = false };
- enum { IsPod = true };
- enum { IsVolatile = false };
- enum { IsConstant = false };
- enum { IsPointer = false };
- enum { IsReference = false };
+namespace {
+ template <typename T>
+ struct TTypeTraitsExpected;
+
+ template <>
+ struct TTypeTraitsExpected<void> {
+ enum { IsIntegral = false };
+ enum { IsArithmetic = false };
+ enum { IsPod = true };
+ enum { IsVolatile = false };
+ enum { IsConstant = false };
+ enum { IsPointer = false };
+ enum { IsReference = false };
enum { IsLvalueReference = false };
enum { IsRvalueReference = false };
- enum { IsArray = false };
- enum { IsClassType = false };
- enum { IsVoid = true };
- enum { IsEnum = false };
- };
-
- template <>
- struct TTypeTraitsExpected<int>: public TTypeTraitsExpected<void> {
- enum { IsIntegral = true };
- enum { IsArithmetic = true };
- enum { IsVoid = false };
- };
-
- template <>
+ enum { IsArray = false };
+ enum { IsClassType = false };
+ enum { IsVoid = true };
+ enum { IsEnum = false };
+ };
+
+ template <>
+ struct TTypeTraitsExpected<int>: public TTypeTraitsExpected<void> {
+ enum { IsIntegral = true };
+ enum { IsArithmetic = true };
+ enum { IsVoid = false };
+ };
+
+ template <>
struct TTypeTraitsExpected<size_t>: public TTypeTraitsExpected<int> {
- };
-
- template <>
+ };
+
+ template <>
struct TTypeTraitsExpected<float>: public TTypeTraitsExpected<int> {
- enum { IsIntegral = false };
- };
-
- template <>
+ enum { IsIntegral = false };
+ };
+
+ template <>
struct TTypeTraitsExpected<long double>: public TTypeTraitsExpected<float> {
- };
-
- template <>
+ };
+
+ template <>
struct TTypeTraitsExpected<const int>: public TTypeTraitsExpected<int> {
- enum { IsConstant = true };
- };
-
- template <>
+ enum { IsConstant = true };
+ };
+
+ template <>
struct TTypeTraitsExpected<volatile int>: public TTypeTraitsExpected<int> {
- enum { IsVolatile = true };
- };
-
- template <>
+ enum { IsVolatile = true };
+ };
+
+ template <>
struct TTypeTraitsExpected<ETestEnum>: public TTypeTraitsExpected<int> {
- enum { IsIntegral = false };
- enum { IsArithmetic = false };
- enum { IsEnum = true };
- };
-
- template <>
+ enum { IsIntegral = false };
+ enum { IsArithmetic = false };
+ enum { IsEnum = true };
+ };
+
+ template <>
struct TTypeTraitsExpected<TPodClass>: public TTypeTraitsExpected<void> {
- enum { IsClassType = true };
- enum { IsVoid = false };
- };
-
- template <>
+ enum { IsClassType = true };
+ enum { IsVoid = false };
+ };
+
+ template <>
struct TTypeTraitsExpected<TNonPodClass>: public TTypeTraitsExpected<TPodClass> {
- enum { IsPod = false };
- };
-
- template <>
+ enum { IsPod = false };
+ };
+
+ template <>
struct TTypeTraitsExpected<TNonPodClass&>: public TTypeTraitsExpected<TNonPodClass> {
- enum { IsClassType = false };
- enum { IsReference = true };
+ enum { IsClassType = false };
+ enum { IsReference = true };
enum { IsLvalueReference = true };
- };
-
+ };
+
template <>
struct TTypeTraitsExpected<TNonPodClass&&>: public TTypeTraitsExpected<TNonPodClass> {
enum { IsClassType = false };
@@ -342,25 +342,25 @@ namespace {
enum { IsRvalueReference = true };
};
- template <>
+ template <>
struct TTypeTraitsExpected<const TNonPodClass&>: public TTypeTraitsExpected<TNonPodClass&> {
- };
-
- template <>
+ };
+
+ template <>
struct TTypeTraitsExpected<float*>: public TTypeTraitsExpected<int> {
- enum { IsIntegral = false };
- enum { IsArithmetic = false };
- enum { IsPointer = true };
- };
-
- template <>
+ enum { IsIntegral = false };
+ enum { IsArithmetic = false };
+ enum { IsPointer = true };
+ };
+
+ template <>
struct TTypeTraitsExpected<float&>: public TTypeTraitsExpected<float*> {
- enum { IsPointer = false };
- enum { IsReference = true };
+ enum { IsPointer = false };
+ enum { IsReference = true };
enum { IsLvalueReference = true };
- };
-
- template <>
+ };
+
+ template <>
struct TTypeTraitsExpected<float&&>: public TTypeTraitsExpected<float*> {
enum { IsPointer = false };
enum { IsReference = true };
@@ -369,22 +369,22 @@ namespace {
template <>
struct TTypeTraitsExpected<const float&>: public TTypeTraitsExpected<float&> {
- };
-
- template <>
+ };
+
+ template <>
struct TTypeTraitsExpected<float[17]>: public TTypeTraitsExpected<int> {
- enum { IsIntegral = false };
- enum { IsArithmetic = false };
- enum { IsArray = true };
- };
-}
-
+ enum { IsIntegral = false };
+ enum { IsArithmetic = false };
+ enum { IsArray = true };
+ };
+}
+
#define UNIT_ASSERT_EQUAL_ENUM(expected, actual) UNIT_ASSERT_VALUES_EQUAL((bool)(expected), (bool)(actual))
-
+
Y_UNIT_TEST_SUITE(TTypeTraitsTestNg) {
- template <typename T>
- void TestImpl() {
- //UNIT_ASSERT_EQUAL_ENUM(TTypeTraitsExpected<T>::IsPod, TTypeTraits<T>::IsPod);
+ template <typename T>
+ void TestImpl() {
+ //UNIT_ASSERT_EQUAL_ENUM(TTypeTraitsExpected<T>::IsPod, TTypeTraits<T>::IsPod);
UNIT_ASSERT_EQUAL_ENUM(TTypeTraitsExpected<T>::IsVoid, std::is_void<T>::value);
UNIT_ASSERT_EQUAL_ENUM(TTypeTraitsExpected<T>::IsEnum, std::is_enum<T>::value);
UNIT_ASSERT_EQUAL_ENUM(TTypeTraitsExpected<T>::IsIntegral, std::is_integral<T>::value);
@@ -397,30 +397,30 @@ Y_UNIT_TEST_SUITE(TTypeTraitsTestNg) {
UNIT_ASSERT_EQUAL_ENUM(TTypeTraitsExpected<T>::IsRvalueReference, std::is_rvalue_reference<T>::value);
UNIT_ASSERT_EQUAL_ENUM(TTypeTraitsExpected<T>::IsArray, std::is_array<T>::value);
UNIT_ASSERT_EQUAL_ENUM(TTypeTraitsExpected<T>::IsClassType, std::is_class<T>::value);
- }
-
+ }
+
#define TYPE_TEST(name, type) \
Y_UNIT_TEST(name) { \
TestImpl<type>(); \
}
-
- TYPE_TEST(Void, void)
- TYPE_TEST(Int, int)
- TYPE_TEST(Float, float)
- TYPE_TEST(LongDouble, long double)
- TYPE_TEST(SizeT, size_t)
- TYPE_TEST(VolatileInt, volatile int)
- TYPE_TEST(ConstInt, const int)
- TYPE_TEST(Enum, ETestEnum)
- TYPE_TEST(FloatPointer, float*)
- TYPE_TEST(FloatReference, float&)
- TYPE_TEST(FloatConstReference, const float&)
- TYPE_TEST(FloatArray, float[17])
+
+ TYPE_TEST(Void, void)
+ TYPE_TEST(Int, int)
+ TYPE_TEST(Float, float)
+ TYPE_TEST(LongDouble, long double)
+ TYPE_TEST(SizeT, size_t)
+ TYPE_TEST(VolatileInt, volatile int)
+ TYPE_TEST(ConstInt, const int)
+ TYPE_TEST(Enum, ETestEnum)
+ TYPE_TEST(FloatPointer, float*)
+ TYPE_TEST(FloatReference, float&)
+ TYPE_TEST(FloatConstReference, const float&)
+ TYPE_TEST(FloatArray, float[17])
TYPE_TEST(PodClass, TPodClass)
TYPE_TEST(NonPodClass, TNonPodClass)
TYPE_TEST(NonPodClassReference, TNonPodClass&)
TYPE_TEST(NonPodClassConstReference, const TNonPodClass&)
-}
+}
enum E4 {
X
diff --git a/util/generic/vector_ut.cpp b/util/generic/vector_ut.cpp
index be27286038..0f6b4037a0 100644
--- a/util/generic/vector_ut.cpp
+++ b/util/generic/vector_ut.cpp
@@ -1,13 +1,13 @@
#include "vector.h"
-
+
#include <library/cpp/testing/unittest/registar.h>
#include <utility>
#include "yexception.h"
-
+
#include <stdexcept>
-class TYVectorTest: public TTestBase {
+class TYVectorTest: public TTestBase {
UNIT_TEST_SUITE(TYVectorTest);
UNIT_TEST(TestConstructorsAndAssignments)
UNIT_TEST(TestTildeEmptyToNull)
@@ -92,23 +92,23 @@ private:
}
// Copy-paste of STLPort tests
-
+
void Test1() {
TVector<int> v1; // Empty vector of integers.
-
+
UNIT_ASSERT(v1.empty() == true);
UNIT_ASSERT(v1.size() == 0);
UNIT_ASSERT(!v1);
-
+
// UNIT_ASSERT(v1.max_size() == INT_MAX / sizeof(int));
// cout << "max_size = " << v1.max_size() << endl;
v1.push_back(42); // Add an integer to the vector.
-
+
UNIT_ASSERT(v1.size() == 1);
UNIT_ASSERT(v1);
-
+
UNIT_ASSERT(v1[0] == 42);
-
+
{
TVector<TVector<int>> vect(10);
TVector<TVector<int>>::iterator it(vect.begin()), end(vect.end());
@@ -117,102 +117,102 @@ private:
UNIT_ASSERT((*it).size() == 0);
UNIT_ASSERT((*it).capacity() == 0);
UNIT_ASSERT((*it).begin() == (*it).end());
- }
- }
+ }
+ }
}
-
+
void Test2() {
TVector<double> v1; // Empty vector of doubles.
v1.push_back(32.1);
v1.push_back(40.5);
TVector<double> v2; // Another empty vector of doubles.
v2.push_back(3.56);
-
+
UNIT_ASSERT(v1.size() == 2);
UNIT_ASSERT(v1[0] == 32.1);
UNIT_ASSERT(v1[1] == 40.5);
-
+
UNIT_ASSERT(v2.size() == 1);
UNIT_ASSERT(v2[0] == 3.56);
v1.swap(v2); // Swap the vector's contents.
-
+
UNIT_ASSERT(v1.size() == 1);
UNIT_ASSERT(v1[0] == 3.56);
-
+
UNIT_ASSERT(v2.size() == 2);
UNIT_ASSERT(v2[0] == 32.1);
UNIT_ASSERT(v2[1] == 40.5);
-
+
v2 = v1; // Assign one vector to another.
-
+
UNIT_ASSERT(v2.size() == 1);
UNIT_ASSERT(v2[0] == 3.56);
}
-
+
void Test3() {
using vec_type = TVector<char>;
-
+
vec_type v1; // Empty vector of characters.
v1.push_back('h');
v1.push_back('i');
-
+
UNIT_ASSERT(v1.size() == 2);
UNIT_ASSERT(v1[0] == 'h');
UNIT_ASSERT(v1[1] == 'i');
-
+
vec_type v2(v1.begin(), v1.end());
v2[1] = 'o'; // Replace second character.
-
+
UNIT_ASSERT(v2.size() == 2);
UNIT_ASSERT(v2[0] == 'h');
UNIT_ASSERT(v2[1] == 'o');
-
+
UNIT_ASSERT((v1 == v2) == false);
-
+
UNIT_ASSERT((v1 < v2) == true);
}
-
+
void Test4() {
TVector<int> v(4);
-
+
v[0] = 1;
v[1] = 4;
v[2] = 9;
v[3] = 16;
-
+
UNIT_ASSERT(v.front() == 1);
UNIT_ASSERT(v.back() == 16);
-
+
v.push_back(25);
-
+
UNIT_ASSERT(v.back() == 25);
UNIT_ASSERT(v.size() == 5);
-
+
v.pop_back();
-
+
UNIT_ASSERT(v.back() == 16);
UNIT_ASSERT(v.size() == 4);
}
-
+
void Test5() {
int array[] = {1, 4, 9, 16};
-
+
TVector<int> v(array, array + 4);
-
+
UNIT_ASSERT(v.size() == 4);
-
+
UNIT_ASSERT(v[0] == 1);
UNIT_ASSERT(v[1] == 4);
UNIT_ASSERT(v[2] == 9);
UNIT_ASSERT(v[3] == 16);
}
-
+
void Test6() {
int array[] = {1, 4, 9, 16, 25, 36};
-
+
TVector<int> v(array, array + 6);
TVector<int>::iterator vit;
-
+
UNIT_ASSERT(v.size() == 6);
UNIT_ASSERT(v[0] == 1);
UNIT_ASSERT(v[1] == 4);
@@ -220,57 +220,57 @@ private:
UNIT_ASSERT(v[3] == 16);
UNIT_ASSERT(v[4] == 25);
UNIT_ASSERT(v[5] == 36);
-
+
vit = v.erase(v.begin()); // Erase first element.
UNIT_ASSERT(*vit == 4);
-
+
UNIT_ASSERT(v.size() == 5);
UNIT_ASSERT(v[0] == 4);
UNIT_ASSERT(v[1] == 9);
UNIT_ASSERT(v[2] == 16);
UNIT_ASSERT(v[3] == 25);
UNIT_ASSERT(v[4] == 36);
-
+
vit = v.erase(v.end() - 1); // Erase last element.
UNIT_ASSERT(vit == v.end());
-
+
UNIT_ASSERT(v.size() == 4);
UNIT_ASSERT(v[0] == 4);
UNIT_ASSERT(v[1] == 9);
UNIT_ASSERT(v[2] == 16);
UNIT_ASSERT(v[3] == 25);
-
+
v.erase(v.begin() + 1, v.end() - 1); // Erase all but first and last.
-
+
UNIT_ASSERT(v.size() == 2);
UNIT_ASSERT(v[0] == 4);
UNIT_ASSERT(v[1] == 25);
}
-
+
void Test7() {
int array1[] = {1, 4, 25};
int array2[] = {9, 16};
-
+
TVector<int> v(array1, array1 + 3);
TVector<int>::iterator vit;
vit = v.insert(v.begin(), 0); // Insert before first element.
UNIT_ASSERT(*vit == 0);
-
+
vit = v.insert(v.end(), 36); // Insert after last element.
UNIT_ASSERT(*vit == 36);
-
+
UNIT_ASSERT(v.size() == 5);
UNIT_ASSERT(v[0] == 0);
UNIT_ASSERT(v[1] == 1);
UNIT_ASSERT(v[2] == 4);
UNIT_ASSERT(v[3] == 25);
UNIT_ASSERT(v[4] == 36);
-
+
// Insert contents of array2 before fourth element.
v.insert(v.begin() + 3, array2, array2 + 2);
-
+
UNIT_ASSERT(v.size() == 7);
-
+
UNIT_ASSERT(v[0] == 0);
UNIT_ASSERT(v[1] == 1);
UNIT_ASSERT(v[2] == 4);
@@ -278,11 +278,11 @@ private:
UNIT_ASSERT(v[4] == 16);
UNIT_ASSERT(v[5] == 25);
UNIT_ASSERT(v[6] == 36);
-
+
size_t curCapacity = v.capacity();
v.clear();
UNIT_ASSERT(v.empty());
-
+
//check that clear save reserved data
UNIT_ASSERT_EQUAL(curCapacity, v.capacity());
@@ -294,22 +294,22 @@ private:
UNIT_ASSERT(v[3] == 10);
UNIT_ASSERT(v[4] == 10);
}
-
+
struct TestStruct {
unsigned int a[3];
};
-
+
void TestCapacity() {
{
TVector<int> v;
-
+
UNIT_ASSERT(v.capacity() == 0);
v.push_back(42);
UNIT_ASSERT(v.capacity() >= 1);
v.reserve(5000);
UNIT_ASSERT(v.capacity() >= 5000);
}
-
+
{
TVector<int> v(Reserve(100));
@@ -322,18 +322,18 @@ private:
TVector<TestStruct> va;
va.reserve(1);
va.reserve(2);
- }
+ }
}
-
+
void TestAt() {
TVector<int> v;
TVector<int> const& cv = v;
-
+
v.push_back(10);
UNIT_ASSERT(v.at(0) == 10);
v.at(0) = 20;
UNIT_ASSERT(cv.at(0) == 20);
-
+
for (;;) {
try {
v.at(1) = 20;
@@ -342,15 +342,15 @@ private:
return;
} catch (...) {
UNIT_ASSERT(false);
- }
- }
+ }
+ }
}
-
+
void TestPointer() {
TVector<int*> v1;
TVector<int*> v2 = v1;
TVector<int*> v3;
-
+
v3.insert(v3.end(), v1.begin(), v1.end());
}
@@ -358,25 +358,25 @@ private:
TVector<int> ref;
for (int i = 0; i < 5; ++i) {
ref.push_back(i);
- }
-
+ }
+
TVector<TVector<int>> v_v_int(1, ref);
v_v_int.push_back(v_v_int[0]);
v_v_int.push_back(ref);
v_v_int.push_back(v_v_int[0]);
v_v_int.push_back(v_v_int[0]);
v_v_int.push_back(ref);
-
+
TVector<TVector<int>>::iterator vvit(v_v_int.begin()), vvitEnd(v_v_int.end());
for (; vvit != vvitEnd; ++vvit) {
UNIT_ASSERT(*vvit == ref);
- }
+ }
}
-
+
struct Point {
int x, y;
};
-
+
struct PointEx: public Point {
PointEx()
: builtFromBase(false)
@@ -386,37 +386,37 @@ private:
: builtFromBase(true)
{
}
-
+
bool builtFromBase;
};
-
+
void TestIterators() {
TVector<int> vint(10, 0);
TVector<int> const& crvint = vint;
-
+
UNIT_ASSERT(vint.begin() == vint.begin());
UNIT_ASSERT(crvint.begin() == vint.begin());
UNIT_ASSERT(vint.begin() == crvint.begin());
UNIT_ASSERT(crvint.begin() == crvint.begin());
-
+
UNIT_ASSERT(vint.begin() != vint.end());
UNIT_ASSERT(crvint.begin() != vint.end());
UNIT_ASSERT(vint.begin() != crvint.end());
UNIT_ASSERT(crvint.begin() != crvint.end());
-
+
UNIT_ASSERT(vint.rbegin() == vint.rbegin());
// Not Standard:
//UNIT_ASSERT(vint.rbegin() == crvint.rbegin());
//UNIT_ASSERT(crvint.rbegin() == vint.rbegin());
UNIT_ASSERT(crvint.rbegin() == crvint.rbegin());
-
+
UNIT_ASSERT(vint.rbegin() != vint.rend());
// Not Standard:
//UNIT_ASSERT(vint.rbegin() != crvint.rend());
//UNIT_ASSERT(crvint.rbegin() != vint.rend());
UNIT_ASSERT(crvint.rbegin() != crvint.rend());
}
-
+
void TestShrink() {
TVector<int> v;
v.resize(1000);
@@ -429,8 +429,8 @@ private:
}
/* This test check a potential issue with empty base class
- * optimization. Some compilers (VC6) do not implement it
- * correctly resulting ina wrong behavior. */
+ * optimization. Some compilers (VC6) do not implement it
+ * correctly resulting ina wrong behavior. */
void TestEbo() {
// We use heap memory as test failure can corrupt vector internal
// representation making executable crash on vector destructor invocation.
@@ -439,36 +439,36 @@ private:
using V = TVector<int>;
V* pv1 = new V(1, 1);
V* pv2 = new V(10, 2);
-
+
size_t v1Capacity = pv1->capacity();
size_t v2Capacity = pv2->capacity();
-
+
pv1->swap(*pv2);
-
+
UNIT_ASSERT(pv1->size() == 10);
UNIT_ASSERT(pv1->capacity() == v2Capacity);
UNIT_ASSERT((*pv1)[5] == 2);
-
+
UNIT_ASSERT(pv2->size() == 1);
UNIT_ASSERT(pv2->capacity() == v1Capacity);
UNIT_ASSERT((*pv2)[0] == 1);
-
+
delete pv2;
delete pv1;
}
-
+
void TestFillInConstructor() {
for (int k = 0; k < 3; ++k) {
TVector<int> v(100);
UNIT_ASSERT_VALUES_EQUAL(100u, v.size());
for (size_t i = 0; i < v.size(); ++i) {
UNIT_ASSERT_VALUES_EQUAL(0, v[i]);
- }
+ }
// fill with garbage for the next iteration
for (size_t i = 0; i < v.size(); ++i) {
v[i] = 10;
}
- }
+ }
}
struct TPod {
@@ -591,6 +591,6 @@ private:
CheckInitializeList(v);
}
}
-};
-
-UNIT_TEST_SUITE_REGISTRATION(TYVectorTest);
+};
+
+UNIT_TEST_SUITE_REGISTRATION(TYVectorTest);
diff --git a/util/generic/ylimits.h b/util/generic/ylimits.h
index e6a52a340f..fe42b4dfc0 100644
--- a/util/generic/ylimits.h
+++ b/util/generic/ylimits.h
@@ -2,10 +2,10 @@
#include <limits>
-#if defined(max) || defined(min)
+#if defined(max) || defined(min)
#error "stop defining 'min' and 'max' macros, evil people"
-#endif
-
+#endif
+
template <class T>
static constexpr T Max() noexcept {
return std::numeric_limits<T>::max();
diff --git a/util/generic/ymath_ut.cpp b/util/generic/ymath_ut.cpp
index 18103fa3c9..29190b55eb 100644
--- a/util/generic/ymath_ut.cpp
+++ b/util/generic/ymath_ut.cpp
@@ -12,13 +12,13 @@ template <class T>
static inline T SlowClp2(T t) noexcept {
Y_ASSERT(t > 0);
- T ret = 1;
+ T ret = 1;
- while (ret < t) {
- ret *= 2;
+ while (ret < t) {
+ ret *= 2;
}
- return ret;
+ return ret;
}
class TMathTest: public TTestBase {
@@ -50,7 +50,7 @@ private:
inline void TestIsValidFloat() {
UNIT_ASSERT(IsValidFloat(-Max<double>() / 2.));
}
-
+
inline void TestClpSimple() {
UNIT_ASSERT_EQUAL(FastClp2<ui32>(12), 16);
UNIT_ASSERT_EQUAL(FastClp2<ui16>(11), 16);
@@ -83,19 +83,19 @@ void TMathTest::TestSqr() {
}
void TMathTest::TestClp2() {
- for (ui8 i = 1; i < 127; ++i) {
+ for (ui8 i = 1; i < 127; ++i) {
UNIT_ASSERT_EQUAL(SlowClp2(i), FastClp2(i));
}
- for (ui16 i = 1; i < 255; ++i) {
+ for (ui16 i = 1; i < 255; ++i) {
UNIT_ASSERT_EQUAL(SlowClp2(i), FastClp2(i));
}
- for (ui32 i = 1; i < 255; ++i) {
+ for (ui32 i = 1; i < 255; ++i) {
UNIT_ASSERT_EQUAL(SlowClp2(i), FastClp2(i));
}
- for (ui64 i = 1; i < 255; ++i) {
+ for (ui64 i = 1; i < 255; ++i) {
UNIT_ASSERT_EQUAL(SlowClp2(i), FastClp2(i));
}