aboutsummaryrefslogtreecommitdiffstats
path: root/util/generic
diff options
context:
space:
mode:
authortender-bum <tender-bum@yandex-team.ru>2022-02-10 16:50:01 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:50:01 +0300
commit4aef354b224559d2b031487a10d4f5cc6e82e95a (patch)
tree5d5cb817648f650d76cf1076100726fd9b8448e8 /util/generic
parentc78b06a63de7beec995c1007bc5332bdf3d75b69 (diff)
downloadydb-4aef354b224559d2b031487a10d4f5cc6e82e95a.tar.gz
Restoring authorship annotation for <tender-bum@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util/generic')
-rw-r--r--util/generic/algorithm.h66
-rw-r--r--util/generic/algorithm_ut.cpp34
-rw-r--r--util/generic/bitops.h8
-rw-r--r--util/generic/hash.h10
-rw-r--r--util/generic/intrlist.h2
-rw-r--r--util/generic/is_in.h2
-rw-r--r--util/generic/maybe.h218
-rw-r--r--util/generic/maybe_traits.h300
-rw-r--r--util/generic/maybe_ut.cpp98
-rw-r--r--util/generic/overloaded.cpp2
-rw-r--r--util/generic/overloaded.h16
-rw-r--r--util/generic/overloaded_ut.cpp74
-rw-r--r--util/generic/ptr_ut.cpp6
-rw-r--r--util/generic/serialized_enum_ut.cpp10
-rw-r--r--util/generic/strbase.h2
-rw-r--r--util/generic/typelist.h54
-rw-r--r--util/generic/typelist_ut.cpp18
-rw-r--r--util/generic/typetraits.h88
-rw-r--r--util/generic/typetraits_ut.cpp18
-rw-r--r--util/generic/utility.h32
-rw-r--r--util/generic/variant.h8
21 files changed, 533 insertions, 533 deletions
diff --git a/util/generic/algorithm.h b/util/generic/algorithm.h
index 221e4c6ad0..badfb88993 100644
--- a/util/generic/algorithm.h
+++ b/util/generic/algorithm.h
@@ -454,27 +454,27 @@ static inline void Rotate(T f, T m, T l) {
}
template <typename It, typename Val>
-Val Accumulate(It begin, It end, Val val) {
- // std::move since C++20
- return std::accumulate(begin, end, std::move(val));
+Val Accumulate(It begin, It end, Val val) {
+ // std::move since C++20
+ return std::accumulate(begin, end, std::move(val));
}
template <typename It, typename Val, typename BinOp>
-Val Accumulate(It begin, It end, Val val, BinOp binOp) {
- // std::move since C++20
- return std::accumulate(begin, end, std::move(val), binOp);
+Val Accumulate(It begin, It end, Val val, BinOp binOp) {
+ // std::move since C++20
+ return std::accumulate(begin, end, std::move(val), binOp);
}
-template <typename C, typename Val>
-Val Accumulate(const C& c, Val val) {
- // std::move since C++20
- return Accumulate(std::begin(c), std::end(c), std::move(val));
+template <typename C, typename Val>
+Val Accumulate(const C& c, Val val) {
+ // std::move since C++20
+ return Accumulate(std::begin(c), std::end(c), std::move(val));
}
-template <typename C, typename Val, typename BinOp>
-Val Accumulate(const C& c, Val val, BinOp binOp) {
- // std::move since C++20
- return Accumulate(std::begin(c), std::end(c), std::move(val), binOp);
+template <typename C, typename Val, typename BinOp>
+Val Accumulate(const C& c, Val val, BinOp binOp) {
+ // std::move since C++20
+ return Accumulate(std::begin(c), std::end(c), std::move(val), binOp);
}
template <typename It1, typename It2, typename Val>
@@ -549,19 +549,19 @@ auto MinElementBy(const C& c, F&& func) {
return MinElementBy(std::begin(c), std::end(c), std::forward<F>(func));
}
-template <class TOp, class... TArgs>
-void ApplyToMany(TOp op, TArgs&&... args) {
+template <class TOp, class... TArgs>
+void ApplyToMany(TOp op, TArgs&&... args) {
int dummy[] = {((void)op(std::forward<TArgs>(args)), 0)...};
- Y_UNUSED(dummy);
-}
-
+ Y_UNUSED(dummy);
+}
+
template <class TI, class TOp>
-inline void ForEach(TI f, TI l, TOp op) {
+inline void ForEach(TI f, TI l, TOp op) {
std::for_each(f, l, op);
}
-namespace NPrivate {
- template <class T, class TOp, size_t... Is>
+namespace NPrivate {
+ template <class T, class TOp, size_t... Is>
constexpr bool AllOfImpl(T&& t, TOp&& op, std::index_sequence<Is...>) {
#if _LIBCPP_STD_VER >= 17
return (true && ... && op(std::get<Is>(std::forward<T>(t))));
@@ -592,13 +592,13 @@ namespace NPrivate {
#if _LIBCPP_STD_VER >= 17
(..., op(std::get<Is>(std::forward<T>(t))));
#else
- ::ApplyToMany(std::forward<TOp>(op), std::get<Is>(std::forward<T>(t))...);
+ ::ApplyToMany(std::forward<TOp>(op), std::get<Is>(std::forward<T>(t))...);
#endif
- }
-}
-
+ }
+}
+
// check that TOp return true for all of element from tuple T
-template <class T, class TOp>
+template <class T, class TOp>
constexpr ::TEnableIfTuple<T, bool> AllOf(T&& t, TOp&& op) {
return ::NPrivate::AllOfImpl(
std::forward<T>(t),
@@ -617,12 +617,12 @@ constexpr ::TEnableIfTuple<T, bool> AnyOf(T&& t, TOp&& op) {
template <class T, class TOp>
constexpr ::TEnableIfTuple<T> ForEach(T&& t, TOp&& op) {
- ::NPrivate::ForEachImpl(
- std::forward<T>(t),
- std::forward<TOp>(op),
- std::make_index_sequence<std::tuple_size<std::decay_t<T>>::value>{});
-}
-
+ ::NPrivate::ForEachImpl(
+ std::forward<T>(t),
+ std::forward<TOp>(op),
+ std::make_index_sequence<std::tuple_size<std::decay_t<T>>::value>{});
+}
+
template <class T1, class T2, class O>
static inline void Transform(T1 b, T1 e, T2 o, O f) {
std::transform(b, e, o, f);
diff --git a/util/generic/algorithm_ut.cpp b/util/generic/algorithm_ut.cpp
index 632677a3c4..8d732fcc0c 100644
--- a/util/generic/algorithm_ut.cpp
+++ b/util/generic/algorithm_ut.cpp
@@ -696,12 +696,12 @@ Y_UNIT_TEST_SUITE(TAlgorithm) {
MinElementBy(empty, functor);
}
- Y_UNIT_TEST(TestApplyToMany) {
- int res = 0;
- ApplyToMany([&res](auto v) { res += v; }, 1, 2, 3, 4, 5);
- UNIT_ASSERT_EQUAL(res, 15);
-
- struct TVisitor {
+ Y_UNIT_TEST(TestApplyToMany) {
+ int res = 0;
+ ApplyToMany([&res](auto v) { res += v; }, 1, 2, 3, 4, 5);
+ UNIT_ASSERT_EQUAL(res, 15);
+
+ struct TVisitor {
TVisitor(int& acc)
: Acc(acc)
{
@@ -712,20 +712,20 @@ Y_UNIT_TEST_SUITE(TAlgorithm) {
void operator()(int v) {
Acc += v * 2;
};
- int& Acc;
- };
+ int& Acc;
+ };
TString s{"8-800-555-35-35"};
ApplyToMany(TVisitor{res = 0}, 1, s, 5, s);
- UNIT_ASSERT_EQUAL(res, 12 + 2 * static_cast<int>(s.size()));
- }
-
- Y_UNIT_TEST(TestTupleForEach) {
+ UNIT_ASSERT_EQUAL(res, 12 + 2 * static_cast<int>(s.size()));
+ }
+
+ Y_UNIT_TEST(TestTupleForEach) {
ForEach(std::tuple<>{}, [&](auto) { UNIT_ASSERT(false); });
- auto t = std::make_tuple(5, 6, 2, 3, 6);
- ForEach(t, [](auto& v) { v *= -1; });
- UNIT_ASSERT_EQUAL(t, std::make_tuple(-5, -6, -2, -3, -6));
- }
-
+ auto t = std::make_tuple(5, 6, 2, 3, 6);
+ ForEach(t, [](auto& v) { v *= -1; });
+ UNIT_ASSERT_EQUAL(t, std::make_tuple(-5, -6, -2, -3, -6));
+ }
+
Y_UNIT_TEST(TestTupleAllOf) {
UNIT_ASSERT(AllOf(std::tuple<>{}, [](auto) { return false; }));
UNIT_ASSERT(!AllOf(std::make_tuple(1, 2, 0, 4, 5), [&](auto v) { UNIT_ASSERT_LT(v, 3); return 0 != v; }));
diff --git a/util/generic/bitops.h b/util/generic/bitops.h
index a1862b1d61..2db15fc59b 100644
--- a/util/generic/bitops.h
+++ b/util/generic/bitops.h
@@ -1,7 +1,7 @@
#pragma once
#include "ylimits.h"
-#include "typelist.h"
+#include "typelist.h"
#include <util/system/compiler.h>
#include <util/system/yassert.h>
@@ -208,7 +208,7 @@ namespace NBitOps {
template <typename T>
static inline T FastClp2(T t) noexcept {
Y_ASSERT(t > 0);
- using TCvt = typename ::TUnsignedInts::template TSelectBy<TSizeOfPredicate<sizeof(T)>::template TResult>::type;
+ using TCvt = typename ::TUnsignedInts::template TSelectBy<TSizeOfPredicate<sizeof(T)>::template TResult>::type;
return 1 + ::NBitOps::NPrivate::TClp2Helper<sizeof(TCvt) * 4, T>::Calc(static_cast<TCvt>(t));
}
@@ -226,7 +226,7 @@ Y_CONST_FUNCTION constexpr bool IsPowerOf2(T v) noexcept {
template <typename T>
static inline unsigned GetValueBitCount(T value) noexcept {
Y_ASSERT(value > 0);
- using TCvt = typename ::TUnsignedInts::template TSelectBy<TSizeOfPredicate<sizeof(T)>::template TResult>::type;
+ using TCvt = typename ::TUnsignedInts::template TSelectBy<TSizeOfPredicate<sizeof(T)>::template TResult>::type;
return ::NBitOps::NPrivate::GetValueBitCountImpl(static_cast<TCvt>(value));
}
@@ -236,7 +236,7 @@ static inline unsigned GetValueBitCount(T value) noexcept {
template <typename T>
static inline unsigned CountTrailingZeroBits(T value) noexcept {
Y_ASSERT(value > 0);
- using TCvt = typename ::TUnsignedInts::template TSelectBy<TSizeOfPredicate<sizeof(T)>::template TResult>::type;
+ using TCvt = typename ::TUnsignedInts::template TSelectBy<TSizeOfPredicate<sizeof(T)>::template TResult>::type;
return ::NBitOps::NPrivate::CountTrailingZeroBitsImpl(static_cast<TCvt>(value));
}
diff --git a/util/generic/hash.h b/util/generic/hash.h
index c6478487d5..e46db21fa9 100644
--- a/util/generic/hash.h
+++ b/util/generic/hash.h
@@ -615,10 +615,10 @@ public:
deinitialize_buckets(buckets);
}
- size_type size() const noexcept {
+ size_type size() const noexcept {
return num_elements;
}
- size_type max_size() const noexcept {
+ size_type max_size() const noexcept {
return size_type(-1);
}
@@ -1521,13 +1521,13 @@ public:
// See hash_ut.cpp
public:
- size_type size() const noexcept {
+ size_type size() const noexcept {
return rep.size();
}
- yssize_t ysize() const noexcept {
+ yssize_t ysize() const noexcept {
return (yssize_t)rep.size();
}
- size_type max_size() const noexcept {
+ size_type max_size() const noexcept {
return rep.max_size();
}
diff --git a/util/generic/intrlist.h b/util/generic/intrlist.h
index 26967cea57..b5d3f2051b 100644
--- a/util/generic/intrlist.h
+++ b/util/generic/intrlist.h
@@ -857,7 +857,7 @@ public:
}
template <class TFunctor>
- inline void ForEach(TFunctor&& functor) const noexcept(noexcept(functor(std::declval<TListItem>().Node()))) {
+ inline void ForEach(TFunctor&& functor) const noexcept(noexcept(functor(std::declval<TListItem>().Node()))) {
TListItem* i = Begin_;
while (i) {
diff --git a/util/generic/is_in.h b/util/generic/is_in.h
index 59d687dc7a..4f175ea5eb 100644
--- a/util/generic/is_in.h
+++ b/util/generic/is_in.h
@@ -17,7 +17,7 @@ namespace NIsInHelper {
Y_HAS_SUBTYPE(key_type, KeyType);
template <class T>
- using TIsAssocCont = TConjunction<THasFindMethod<T>, THasConstIterator<T>, THasKeyType<T>>;
+ using TIsAssocCont = TConjunction<THasFindMethod<T>, THasConstIterator<T>, THasKeyType<T>>;
template <class C, class T, bool isAssoc>
struct TIsInTraits {
diff --git a/util/generic/maybe.h b/util/generic/maybe.h
index b47d6f4cab..34d21aebcd 100644
--- a/util/generic/maybe.h
+++ b/util/generic/maybe.h
@@ -1,8 +1,8 @@
#pragma once
#include <utility>
-
-#include "maybe_traits.h"
+
+#include "maybe_traits.h"
#include "yexception.h"
#include <util/system/align.h>
@@ -37,17 +37,17 @@ constexpr bool operator==(TNothing, TNothing) noexcept {
template <class T, class Policy /*= ::NMaybe::TPolicyUndefinedExcept*/>
class TMaybe: private TMaybeBase<T> {
public:
- using TInPlace = NMaybe::TInPlace;
-
-private:
- static_assert(!std::is_same<std::remove_cv_t<T>, TNothing>::value,
- "Instantiation of TMaybe with a TNothing type is ill-formed");
- static_assert(!std::is_same<std::remove_cv_t<T>, TInPlace>::value,
- "Instantiation of TMaybe with a TInPlace type is ill-formed");
- static_assert(!std::is_reference<T>::value,
- "Instantiation of TMaybe with reference type is ill-formed");
- static_assert(std::is_destructible<T>::value,
- "Instantiation of TMaybe with non-destructible type is ill-formed");
+ using TInPlace = NMaybe::TInPlace;
+
+private:
+ static_assert(!std::is_same<std::remove_cv_t<T>, TNothing>::value,
+ "Instantiation of TMaybe with a TNothing type is ill-formed");
+ static_assert(!std::is_same<std::remove_cv_t<T>, TInPlace>::value,
+ "Instantiation of TMaybe with a TInPlace type is ill-formed");
+ static_assert(!std::is_reference<T>::value,
+ "Instantiation of TMaybe with reference type is ill-formed");
+ static_assert(std::is_destructible<T>::value,
+ "Instantiation of TMaybe with non-destructible type is ill-formed");
template <class U>
struct TConstructibleFromMaybeSomehow {
@@ -72,66 +72,66 @@ private:
std::is_assignable<T&, const TMaybe<U, Policy>&&>::value;
};
- template <class U>
+ template <class U>
struct TImplicitCopyCtor {
public:
static constexpr bool value = std::is_constructible<T, const U&>::value &&
std::is_convertible<const U&, T>::value &&
!TConstructibleFromMaybeSomehow<U>::value;
};
-
- template <class U>
+
+ template <class U>
struct TExplicitCopyCtor {
public:
static constexpr bool value = std::is_constructible<T, const U&>::value &&
!std::is_convertible<const U&, T>::value &&
!TConstructibleFromMaybeSomehow<U>::value;
};
-
- template <class U>
+
+ template <class U>
struct TImplicitMoveCtor {
public:
static constexpr bool value = std::is_constructible<T, U&&>::value &&
std::is_convertible<U&&, T>::value &&
!TConstructibleFromMaybeSomehow<U>::value;
};
-
- template <class U>
+
+ template <class U>
struct TExplicitMoveCtor {
public:
static constexpr bool value = std::is_constructible<T, U&&>::value &&
!std::is_convertible<U&&, T>::value &&
!TConstructibleFromMaybeSomehow<U>::value;
};
-
- template <class U>
+
+ template <class U>
struct TCopyAssignable {
public:
static constexpr bool value = std::is_constructible<T, const U&>::value &&
std::is_assignable<T&, const U&>::value &&
!TAssignableFromMaybeSomehow<U>::value;
};
-
- template <class U>
+
+ template <class U>
struct TMoveAssignable {
public:
static constexpr bool value = std::is_constructible<T, U&&>::value &&
std::is_assignable<T&, U&&>::value &&
!TAssignableFromMaybeSomehow<U>::value;
};
-
+
template <class U>
struct TImplicitAnyCtor {
public:
using UDec = std::decay_t<U>;
-
+
static constexpr bool value = std::is_constructible<T, U>::value &&
std::is_convertible<U, T>::value &&
!std::is_same<UDec, TInPlace>::value &&
!std::is_same<UDec, TMaybe>::value;
};
-
- template <class U>
+
+ template <class U>
struct TExplicitAnyCtor {
public:
using UDec = std::decay_t<U>;
@@ -140,7 +140,7 @@ private:
!std::is_same<UDec, TInPlace>::value &&
!std::is_same<UDec, TMaybe>::value;
};
-
+
template <class U>
struct TAssignableFromAny {
public:
@@ -151,23 +151,23 @@ private:
(!std::is_scalar<T>::value || !std::is_same<UDec, T>::value);
};
- using TBase = TMaybeBase<T>;
+ using TBase = TMaybeBase<T>;
+
+public:
+ using value_type = T;
+ using TValueType = value_type;
-public:
- using value_type = T;
- using TValueType = value_type;
+ TMaybe() noexcept = default;
- TMaybe() noexcept = default;
+ constexpr TMaybe(const TMaybe&) = default;
+ constexpr TMaybe(TMaybe&&) = default;
- constexpr TMaybe(const TMaybe&) = default;
- constexpr TMaybe(TMaybe&&) = default;
-
- template <class... Args>
- constexpr explicit TMaybe(TInPlace, Args&&... args)
+ template <class... Args>
+ constexpr explicit TMaybe(TInPlace, Args&&... args)
: TBase(TInPlace{}, std::forward<Args>(args)...)
{
}
-
+
template <class U, class... TArgs>
constexpr explicit TMaybe(TInPlace, std::initializer_list<U> il, TArgs&&... args)
: TBase(TInPlace{}, il, std::forward<TArgs>(args)...)
@@ -177,77 +177,77 @@ public:
constexpr TMaybe(TNothing) noexcept {
}
- template <class U, class = std::enable_if_t<TImplicitCopyCtor<U>::value>>
- TMaybe(const TMaybe<U, Policy>& right) {
- if (right.Defined()) {
+ template <class U, class = std::enable_if_t<TImplicitCopyCtor<U>::value>>
+ TMaybe(const TMaybe<U, Policy>& right) {
+ if (right.Defined()) {
new (Data()) T(right.GetRef());
- this->Defined_ = true;
+ this->Defined_ = true;
}
}
- template <class U, std::enable_if_t<TExplicitCopyCtor<U>::value, bool> = false>
- explicit TMaybe(const TMaybe<U, Policy>& right) {
- if (right.Defined()) {
+ template <class U, std::enable_if_t<TExplicitCopyCtor<U>::value, bool> = false>
+ explicit TMaybe(const TMaybe<U, Policy>& right) {
+ if (right.Defined()) {
new (Data()) T(right.GetRef());
- this->Defined_ = true;
+ this->Defined_ = true;
}
}
- template <class U, class = std::enable_if_t<TImplicitMoveCtor<U>::value>>
- TMaybe(TMaybe<U, Policy>&& right) noexcept(std::is_nothrow_constructible<T, U&&>::value) {
- if (right.Defined()) {
+ template <class U, class = std::enable_if_t<TImplicitMoveCtor<U>::value>>
+ TMaybe(TMaybe<U, Policy>&& right) noexcept(std::is_nothrow_constructible<T, U&&>::value) {
+ if (right.Defined()) {
new (Data()) T(std::move(right.GetRef()));
- this->Defined_ = true;
+ this->Defined_ = true;
}
}
- template <class U, std::enable_if_t<TExplicitMoveCtor<U>::value, bool> = false>
- explicit TMaybe(TMaybe<U, Policy>&& right) noexcept(std::is_nothrow_constructible<T, U&&>::value) {
- if (right.Defined()) {
+ template <class U, std::enable_if_t<TExplicitMoveCtor<U>::value, bool> = false>
+ explicit TMaybe(TMaybe<U, Policy>&& right) noexcept(std::is_nothrow_constructible<T, U&&>::value) {
+ if (right.Defined()) {
new (Data()) T(std::move(right.GetRef()));
- this->Defined_ = true;
+ this->Defined_ = true;
}
}
- template <class U = T, class = std::enable_if_t<TImplicitAnyCtor<U>::value>>
- constexpr TMaybe(U&& right)
+ template <class U = T, class = std::enable_if_t<TImplicitAnyCtor<U>::value>>
+ constexpr TMaybe(U&& right)
: TBase(TInPlace{}, std::forward<U>(right))
{
}
-
- template <class U = T, std::enable_if_t<TExplicitAnyCtor<U>::value, bool> = false>
- constexpr explicit TMaybe(U&& right)
+
+ template <class U = T, std::enable_if_t<TExplicitAnyCtor<U>::value, bool> = false>
+ constexpr explicit TMaybe(U&& right)
: TBase(TInPlace{}, std::forward<U>(right))
{
}
-
- ~TMaybe() = default;
- constexpr TMaybe& operator=(const TMaybe&) = default;
- constexpr TMaybe& operator=(TMaybe&&) = default;
+ ~TMaybe() = default;
- TMaybe& operator=(TNothing) noexcept {
+ constexpr TMaybe& operator=(const TMaybe&) = default;
+ constexpr TMaybe& operator=(TMaybe&&) = default;
+
+ TMaybe& operator=(TNothing) noexcept {
Clear();
return *this;
}
- template <class U = T>
- std::enable_if_t<TAssignableFromAny<U>::value, TMaybe&> operator=(U&& right) {
+ template <class U = T>
+ std::enable_if_t<TAssignableFromAny<U>::value, TMaybe&> operator=(U&& right) {
if (Defined()) {
- *Data() = std::forward<U>(right);
+ *Data() = std::forward<U>(right);
} else {
- Init(std::forward<U>(right));
+ Init(std::forward<U>(right));
}
return *this;
}
- template <class U>
- std::enable_if_t<TCopyAssignable<U>::value,
+ template <class U>
+ std::enable_if_t<TCopyAssignable<U>::value,
TMaybe&>
operator=(const TMaybe<U, Policy>& right) {
if (right.Defined()) {
if (Defined()) {
- *Data() = right.GetRef();
+ *Data() = right.GetRef();
} else {
Init(right.GetRef());
}
@@ -258,15 +258,15 @@ public:
return *this;
}
- template <class U>
- std::enable_if_t<TMoveAssignable<U>::value,
+ template <class U>
+ std::enable_if_t<TMoveAssignable<U>::value,
TMaybe&>
operator=(TMaybe<U, Policy>&& right) noexcept(
std::is_nothrow_assignable<T&, U&&>::value&& std::is_nothrow_constructible<T, U&&>::value)
- {
+ {
if (right.Defined()) {
if (Defined()) {
- *Data() = std::move(right.GetRef());
+ *Data() = std::move(right.GetRef());
} else {
Init(std::move(right.GetRef()));
}
@@ -277,39 +277,39 @@ public:
return *this;
}
- template <typename... Args>
- T& ConstructInPlace(Args&&... args) {
- Clear();
- Init(std::forward<Args>(args)...);
- return *Data();
- }
-
- void Clear() noexcept {
+ template <typename... Args>
+ T& ConstructInPlace(Args&&... args) {
+ Clear();
+ Init(std::forward<Args>(args)...);
+ return *Data();
+ }
+
+ void Clear() noexcept {
if (Defined()) {
- this->Defined_ = false;
+ this->Defined_ = false;
Data()->~T();
}
}
- constexpr bool Defined() const noexcept {
- return this->Defined_;
+ constexpr bool Defined() const noexcept {
+ return this->Defined_;
}
Y_PURE_FUNCTION constexpr bool Empty() const noexcept {
return !Defined();
}
- void CheckDefined() const {
+ void CheckDefined() const {
if (Y_UNLIKELY(!Defined())) {
Policy::OnEmpty(typeid(TValueType));
}
}
- const T* Get() const noexcept {
+ const T* Get() const noexcept {
return Defined() ? Data() : nullptr;
}
- T* Get() noexcept {
+ T* Get() noexcept {
return Defined() ? Data() : nullptr;
}
@@ -353,27 +353,27 @@ public:
return std::move(GetRef());
}
- constexpr const T* operator->() const {
+ constexpr const T* operator->() const {
return &GetRef();
}
- constexpr T* operator->() {
+ constexpr T* operator->() {
return &GetRef();
}
- constexpr const T& GetOrElse(const T& elseValue) const {
+ constexpr const T& GetOrElse(const T& elseValue) const {
return Defined() ? *Data() : elseValue;
}
- constexpr T& GetOrElse(T& elseValue) {
+ constexpr T& GetOrElse(T& elseValue) {
return Defined() ? *Data() : elseValue;
}
- constexpr const TMaybe& OrElse(const TMaybe& elseValue) const noexcept {
+ constexpr const TMaybe& OrElse(const TMaybe& elseValue) const noexcept {
return Defined() ? *this : elseValue;
}
- constexpr TMaybe& OrElse(TMaybe& elseValue) {
+ constexpr TMaybe& OrElse(TMaybe& elseValue) {
return Defined() ? *this : elseValue;
}
@@ -383,7 +383,7 @@ public:
}
constexpr explicit operator bool() const noexcept {
- return Defined();
+ return Defined();
}
void Save(IOutputStream* out) const {
@@ -392,7 +392,7 @@ public:
::Save<bool>(out, defined);
if (defined) {
- ::Save(out, *Data());
+ ::Save(out, *Data());
}
}
@@ -406,13 +406,13 @@ public:
ConstructInPlace();
}
- ::Load(in, *Data());
+ ::Load(in, *Data());
} else {
Clear();
}
}
- void Swap(TMaybe& other) {
+ void Swap(TMaybe& other) {
if (this->Defined_ == other.Defined_) {
if (this->Defined_) {
::DoSwap(this->Data_, other.Data_);
@@ -428,23 +428,23 @@ public:
}
}
- void swap(TMaybe& other) {
+ void swap(TMaybe& other) {
Swap(other);
}
private:
- constexpr const T* Data() const noexcept {
- return std::addressof(this->Data_);
+ constexpr const T* Data() const noexcept {
+ return std::addressof(this->Data_);
}
- constexpr T* Data() noexcept {
- return std::addressof(this->Data_);
+ constexpr T* Data() noexcept {
+ return std::addressof(this->Data_);
}
template <typename... Args>
- void Init(Args&&... args) {
+ void Init(Args&&... args) {
new (Data()) T(std::forward<Args>(args)...);
- this->Defined_ = true;
+ this->Defined_ = true;
}
};
@@ -712,7 +712,7 @@ constexpr bool operator>=(const U& value, const TMaybe<T, TPolicy>& maybe) {
class IOutputStream;
template <class T, class TPolicy>
-inline IOutputStream& operator<<(IOutputStream& out, const TMaybe<T, TPolicy>& maybe) {
+inline IOutputStream& operator<<(IOutputStream& out, const TMaybe<T, TPolicy>& maybe) {
if (maybe.Defined()) {
out << *maybe;
} else {
diff --git a/util/generic/maybe_traits.h b/util/generic/maybe_traits.h
index d507d8fa34..9e9f56955e 100644
--- a/util/generic/maybe_traits.h
+++ b/util/generic/maybe_traits.h
@@ -1,173 +1,173 @@
-#pragma once
-
+#pragma once
+
#include <memory>
-#include <type_traits>
-#include <initializer_list>
-
-namespace NMaybe {
- struct TInPlace {};
-
- template <class T, bool = std::is_trivially_destructible<T>::value>
- struct TStorageBase {
- constexpr TStorageBase() noexcept
+#include <type_traits>
+#include <initializer_list>
+
+namespace NMaybe {
+ struct TInPlace {};
+
+ template <class T, bool = std::is_trivially_destructible<T>::value>
+ struct TStorageBase {
+ constexpr TStorageBase() noexcept
: NullState_('\0')
{
}
-
- template <class... Args>
- constexpr TStorageBase(TInPlace, Args&&... args)
- : Data_(std::forward<Args>(args)...)
+
+ template <class... Args>
+ constexpr TStorageBase(TInPlace, Args&&... args)
+ : Data_(std::forward<Args>(args)...)
, Defined_(true)
{
}
-
- ~TStorageBase() = default;
-
- union {
- char NullState_;
- T Data_;
- };
- bool Defined_ = false;
- };
-
- template <class T>
- struct TStorageBase<T, false> {
- constexpr TStorageBase() noexcept
+
+ ~TStorageBase() = default;
+
+ union {
+ char NullState_;
+ T Data_;
+ };
+ bool Defined_ = false;
+ };
+
+ template <class T>
+ struct TStorageBase<T, false> {
+ constexpr TStorageBase() noexcept
: NullState_('\0')
{
}
-
- template <class... Args>
- constexpr TStorageBase(TInPlace, Args&&... args)
- : Data_(std::forward<Args>(args)...)
+
+ template <class... Args>
+ constexpr TStorageBase(TInPlace, Args&&... args)
+ : Data_(std::forward<Args>(args)...)
, Defined_(true)
{
}
-
- ~TStorageBase() {
- if (this->Defined_) {
- this->Data_.~T();
- }
- }
-
- union {
- char NullState_;
- T Data_;
- };
- bool Defined_ = false;
- };
-
- // -------------------- COPY CONSTRUCT --------------------
-
- template <class T, bool = std::is_trivially_copy_constructible<T>::value>
+
+ ~TStorageBase() {
+ if (this->Defined_) {
+ this->Data_.~T();
+ }
+ }
+
+ union {
+ char NullState_;
+ T Data_;
+ };
+ bool Defined_ = false;
+ };
+
+ // -------------------- COPY CONSTRUCT --------------------
+
+ template <class T, bool = std::is_trivially_copy_constructible<T>::value>
struct TCopyBase: TStorageBase<T> {
- using TStorageBase<T>::TStorageBase;
- };
-
- template <class T>
+ using TStorageBase<T>::TStorageBase;
+ };
+
+ template <class T>
struct TCopyBase<T, false>: TStorageBase<T> {
- using TStorageBase<T>::TStorageBase;
-
- constexpr TCopyBase() = default;
- constexpr TCopyBase(const TCopyBase& rhs) {
- if (rhs.Defined_) {
- new (std::addressof(this->Data_)) T(rhs.Data_);
- this->Defined_ = true;
- }
- }
- constexpr TCopyBase(TCopyBase&&) = default;
- TCopyBase& operator=(const TCopyBase&) = default;
- TCopyBase& operator=(TCopyBase&&) = default;
- };
-
- // -------------------- MOVE CONSTRUCT --------------------
-
- template <class T, bool = std::is_trivially_move_constructible<T>::value>
+ using TStorageBase<T>::TStorageBase;
+
+ constexpr TCopyBase() = default;
+ constexpr TCopyBase(const TCopyBase& rhs) {
+ if (rhs.Defined_) {
+ new (std::addressof(this->Data_)) T(rhs.Data_);
+ this->Defined_ = true;
+ }
+ }
+ constexpr TCopyBase(TCopyBase&&) = default;
+ TCopyBase& operator=(const TCopyBase&) = default;
+ TCopyBase& operator=(TCopyBase&&) = default;
+ };
+
+ // -------------------- MOVE CONSTRUCT --------------------
+
+ template <class T, bool = std::is_trivially_move_constructible<T>::value>
struct TMoveBase: TCopyBase<T> {
- using TCopyBase<T>::TCopyBase;
- };
-
- template <class T>
+ using TCopyBase<T>::TCopyBase;
+ };
+
+ template <class T>
struct TMoveBase<T, false>: TCopyBase<T> {
- using TCopyBase<T>::TCopyBase;
-
- constexpr TMoveBase() noexcept = default;
- constexpr TMoveBase(const TMoveBase&) = default;
- constexpr TMoveBase(TMoveBase&& rhs) noexcept(std::is_nothrow_move_constructible<T>::value) {
- if (rhs.Defined_) {
- new (std::addressof(this->Data_)) T(std::move(rhs.Data_));
- this->Defined_ = true;
- }
- }
- TMoveBase& operator=(const TMoveBase&) = default;
- TMoveBase& operator=(TMoveBase&&) = default;
- };
-
- // -------------------- COPY ASSIGN --------------------
-
- template <class T, bool = std::is_trivially_copy_assignable<T>::value>
+ using TCopyBase<T>::TCopyBase;
+
+ constexpr TMoveBase() noexcept = default;
+ constexpr TMoveBase(const TMoveBase&) = default;
+ constexpr TMoveBase(TMoveBase&& rhs) noexcept(std::is_nothrow_move_constructible<T>::value) {
+ if (rhs.Defined_) {
+ new (std::addressof(this->Data_)) T(std::move(rhs.Data_));
+ this->Defined_ = true;
+ }
+ }
+ TMoveBase& operator=(const TMoveBase&) = default;
+ TMoveBase& operator=(TMoveBase&&) = default;
+ };
+
+ // -------------------- COPY ASSIGN --------------------
+
+ template <class T, bool = std::is_trivially_copy_assignable<T>::value>
struct TCopyAssignBase: TMoveBase<T> {
- using TMoveBase<T>::TMoveBase;
- };
-
- template <class T>
+ using TMoveBase<T>::TMoveBase;
+ };
+
+ template <class T>
struct TCopyAssignBase<T, false>: TMoveBase<T> {
- using TMoveBase<T>::TMoveBase;
-
- constexpr TCopyAssignBase() noexcept = default;
- constexpr TCopyAssignBase(const TCopyAssignBase&) = default;
- constexpr TCopyAssignBase(TCopyAssignBase&&) = default;
- TCopyAssignBase& operator=(const TCopyAssignBase& rhs) {
- if (this->Defined_) {
- if (rhs.Defined_) {
- this->Data_ = rhs.Data_;
- } else {
- this->Data_.~T();
- this->Defined_ = false;
- }
- } else if (rhs.Defined_) {
- new (std::addressof(this->Data_)) T(rhs.Data_);
- this->Defined_ = true;
- }
- return *this;
- }
- TCopyAssignBase& operator=(TCopyAssignBase&&) = default;
- };
-
- // -------------------- MOVE ASSIGN --------------------
-
- template <class T, bool = std::is_trivially_copy_assignable<T>::value>
+ using TMoveBase<T>::TMoveBase;
+
+ constexpr TCopyAssignBase() noexcept = default;
+ constexpr TCopyAssignBase(const TCopyAssignBase&) = default;
+ constexpr TCopyAssignBase(TCopyAssignBase&&) = default;
+ TCopyAssignBase& operator=(const TCopyAssignBase& rhs) {
+ if (this->Defined_) {
+ if (rhs.Defined_) {
+ this->Data_ = rhs.Data_;
+ } else {
+ this->Data_.~T();
+ this->Defined_ = false;
+ }
+ } else if (rhs.Defined_) {
+ new (std::addressof(this->Data_)) T(rhs.Data_);
+ this->Defined_ = true;
+ }
+ return *this;
+ }
+ TCopyAssignBase& operator=(TCopyAssignBase&&) = default;
+ };
+
+ // -------------------- MOVE ASSIGN --------------------
+
+ template <class T, bool = std::is_trivially_copy_assignable<T>::value>
struct TMoveAssignBase: TCopyAssignBase<T> {
- using TCopyAssignBase<T>::TCopyAssignBase;
- };
-
- template <class T>
+ using TCopyAssignBase<T>::TCopyAssignBase;
+ };
+
+ template <class T>
struct TMoveAssignBase<T, false>: TCopyAssignBase<T> {
- using TCopyAssignBase<T>::TCopyAssignBase;
-
- constexpr TMoveAssignBase() noexcept = default;
- constexpr TMoveAssignBase(const TMoveAssignBase&) = default;
- constexpr TMoveAssignBase(TMoveAssignBase&&) = default;
- TMoveAssignBase& operator=(const TMoveAssignBase&) = default;
- TMoveAssignBase& operator=(TMoveAssignBase&& rhs) noexcept(
+ using TCopyAssignBase<T>::TCopyAssignBase;
+
+ constexpr TMoveAssignBase() noexcept = default;
+ constexpr TMoveAssignBase(const TMoveAssignBase&) = default;
+ constexpr TMoveAssignBase(TMoveAssignBase&&) = default;
+ TMoveAssignBase& operator=(const TMoveAssignBase&) = default;
+ TMoveAssignBase& operator=(TMoveAssignBase&& rhs) noexcept(
std::is_nothrow_move_assignable<T>::value&&
std::is_nothrow_move_constructible<T>::value)
- {
- if (this->Defined_) {
- if (rhs.Defined_) {
- this->Data_ = std::move(rhs.Data_);
- } else {
- this->Data_.~T();
- this->Defined_ = false;
- }
- } else if (rhs.Defined_) {
- new (std::addressof(this->Data_)) T(std::move(rhs.Data_));
- this->Defined_ = true;
- }
- return *this;
- }
- };
-}
-
-template <class T>
-using TMaybeBase = NMaybe::TMoveAssignBase<T>;
+ {
+ if (this->Defined_) {
+ if (rhs.Defined_) {
+ this->Data_ = std::move(rhs.Data_);
+ } else {
+ this->Data_.~T();
+ this->Defined_ = false;
+ }
+ } else if (rhs.Defined_) {
+ new (std::addressof(this->Data_)) T(std::move(rhs.Data_));
+ this->Defined_ = true;
+ }
+ return *this;
+ }
+ };
+}
+
+template <class T>
+using TMaybeBase = NMaybe::TMoveAssignBase<T>;
diff --git a/util/generic/maybe_ut.cpp b/util/generic/maybe_ut.cpp
index 8eb9de6426..2c1a425c5e 100644
--- a/util/generic/maybe_ut.cpp
+++ b/util/generic/maybe_ut.cpp
@@ -21,24 +21,24 @@ public:
};
Y_UNIT_TEST_SUITE(TMaybeTest) {
- Y_UNIT_TEST(TestStatic) {
- using T1 = TMaybe<int>;
- static_assert(std::is_trivially_copy_constructible<T1>::value, "");
- static_assert(std::is_trivially_destructible<T1>::value, "");
-
- using T2 = TMaybe<TString*>;
- static_assert(std::is_trivially_copy_constructible<T2>::value, "");
- static_assert(std::is_trivially_destructible<T2>::value, "");
-
- using T3 = TMaybe<TMaybe<double>>;
- static_assert(std::is_trivially_copy_constructible<T3>::value, "");
- static_assert(std::is_trivially_destructible<T3>::value, "");
-
- using T4 = TMaybe<TString>;
- static_assert(!std::is_trivially_copy_constructible<T4>::value, "");
- static_assert(!std::is_trivially_destructible<T4>::value, "");
- }
-
+ Y_UNIT_TEST(TestStatic) {
+ using T1 = TMaybe<int>;
+ static_assert(std::is_trivially_copy_constructible<T1>::value, "");
+ static_assert(std::is_trivially_destructible<T1>::value, "");
+
+ using T2 = TMaybe<TString*>;
+ static_assert(std::is_trivially_copy_constructible<T2>::value, "");
+ static_assert(std::is_trivially_destructible<T2>::value, "");
+
+ using T3 = TMaybe<TMaybe<double>>;
+ static_assert(std::is_trivially_copy_constructible<T3>::value, "");
+ static_assert(std::is_trivially_destructible<T3>::value, "");
+
+ using T4 = TMaybe<TString>;
+ static_assert(!std::is_trivially_copy_constructible<T4>::value, "");
+ static_assert(!std::is_trivially_destructible<T4>::value, "");
+ }
+
Y_UNIT_TEST(TestWarning) {
TMaybe<size_t> x;
TStringStream ss;
@@ -136,9 +136,9 @@ Y_UNIT_TEST_SUITE(TMaybeTest) {
UNIT_ASSERT(m5 == TMaybe<int>());
UNIT_ASSERT(m5 == Nothing());
UNIT_ASSERT(m5 != TMaybe<int>(5));
-
- m5 = {};
- UNIT_ASSERT(m5.Empty());
+
+ m5 = {};
+ UNIT_ASSERT(m5.Empty());
}
Y_UNIT_TEST(TestInPlace) {
@@ -964,40 +964,40 @@ Y_UNIT_TEST_SUITE(TMaybeTest) {
UNIT_ASSERT_EQUAL(testStructMaybe.GetRef().From_, TestStruct::FromValue);
UNIT_ASSERT_EQUAL(testStructMaybe.GetRef().Value_, 23);
}
-
- Y_UNIT_TEST(TestMaybeConvertion) {
- struct TSrc {};
- struct TDst {
- bool FromMaybeConstructorApplied;
-
- explicit TDst(TSrc)
+
+ Y_UNIT_TEST(TestMaybeConvertion) {
+ struct TSrc {};
+ struct TDst {
+ bool FromMaybeConstructorApplied;
+
+ explicit TDst(TSrc)
: FromMaybeConstructorApplied(false)
{
}
-
- explicit TDst(TMaybe<TSrc>)
+
+ explicit TDst(TMaybe<TSrc>)
: FromMaybeConstructorApplied(true)
{
}
-
- TDst& operator=(TSrc) {
- FromMaybeConstructorApplied = false;
- return *this;
- }
- TDst& operator=(TMaybe<TSrc>) {
- FromMaybeConstructorApplied = true;
- return *this;
- }
- };
-
- auto m = TMaybe<TDst>(TMaybe<TSrc>());
- UNIT_ASSERT(m.Defined());
- UNIT_ASSERT(m->FromMaybeConstructorApplied);
-
- m = TMaybe<TSrc>();
- UNIT_ASSERT(m.Defined());
- UNIT_ASSERT(m->FromMaybeConstructorApplied);
- }
+
+ TDst& operator=(TSrc) {
+ FromMaybeConstructorApplied = false;
+ return *this;
+ }
+ TDst& operator=(TMaybe<TSrc>) {
+ FromMaybeConstructorApplied = true;
+ return *this;
+ }
+ };
+
+ auto m = TMaybe<TDst>(TMaybe<TSrc>());
+ UNIT_ASSERT(m.Defined());
+ UNIT_ASSERT(m->FromMaybeConstructorApplied);
+
+ m = TMaybe<TSrc>();
+ UNIT_ASSERT(m.Defined());
+ UNIT_ASSERT(m->FromMaybeConstructorApplied);
+ }
Y_UNIT_TEST(TestOnEmptyException) {
TMaybe<TStringBuf> v;
diff --git a/util/generic/overloaded.cpp b/util/generic/overloaded.cpp
index 7372126e41..fb6ff88d31 100644
--- a/util/generic/overloaded.cpp
+++ b/util/generic/overloaded.cpp
@@ -1 +1 @@
-#include "overloaded.h"
+#include "overloaded.h"
diff --git a/util/generic/overloaded.h b/util/generic/overloaded.h
index 848d48c712..96a97e44bc 100644
--- a/util/generic/overloaded.h
+++ b/util/generic/overloaded.h
@@ -1,5 +1,5 @@
-#pragma once
-
+#pragma once
+
/**
* Construct an ad-hoc object with an overloaded `operator()`.
*
@@ -47,10 +47,10 @@
* ```
*/
-template <class... Fs>
+template <class... Fs>
struct TOverloaded: Fs... {
- using Fs::operator()...;
-};
-
-template <class... Fs>
-TOverloaded(Fs...) -> TOverloaded<Fs...>;
+ using Fs::operator()...;
+};
+
+template <class... Fs>
+TOverloaded(Fs...) -> TOverloaded<Fs...>;
diff --git a/util/generic/overloaded_ut.cpp b/util/generic/overloaded_ut.cpp
index 43893808e5..f3d73895ad 100644
--- a/util/generic/overloaded_ut.cpp
+++ b/util/generic/overloaded_ut.cpp
@@ -1,55 +1,55 @@
#include <util/generic/overloaded.h>
-
+
#include <library/cpp/testing/unittest/registar.h>
-
-#include <util/generic/variant.h>
-#include <util/generic/algorithm.h>
-
-#include <tuple>
-
-namespace {
- struct TType1 {};
- struct TType2 {};
- struct TType3 {};
-}
-
-Y_UNIT_TEST_SUITE(TOverloadedTest) {
- Y_UNIT_TEST(StaticTest) {
- auto f = TOverloaded{
- [](const TType1&) {},
- [](const TType2&) {},
+
+#include <util/generic/variant.h>
+#include <util/generic/algorithm.h>
+
+#include <tuple>
+
+namespace {
+ struct TType1 {};
+ struct TType2 {};
+ struct TType3 {};
+}
+
+Y_UNIT_TEST_SUITE(TOverloadedTest) {
+ Y_UNIT_TEST(StaticTest) {
+ auto f = TOverloaded{
+ [](const TType1&) {},
+ [](const TType2&) {},
[](const TType3&) {}};
- using F = decltype(f);
- static_assert(std::is_invocable_v<F, TType1>);
- static_assert(std::is_invocable_v<F, TType2>);
- static_assert(std::is_invocable_v<F, TType3>);
- static_assert(!std::is_invocable_v<F, int>);
- static_assert(!std::is_invocable_v<F, double>);
- }
-
- Y_UNIT_TEST(VariantTest) {
+ using F = decltype(f);
+ static_assert(std::is_invocable_v<F, TType1>);
+ static_assert(std::is_invocable_v<F, TType2>);
+ static_assert(std::is_invocable_v<F, TType3>);
+ static_assert(!std::is_invocable_v<F, int>);
+ static_assert(!std::is_invocable_v<F, double>);
+ }
+
+ Y_UNIT_TEST(VariantTest) {
std::variant<int, double, TType1> v = 5;
- int res = 0;
+ int res = 0;
std::visit(TOverloaded{
[&](int val) { res = val; },
[&](double) { res = -1; },
[&](TType1) { res = -1; }},
v);
UNIT_ASSERT_VALUES_EQUAL(res, 5);
- }
-
- Y_UNIT_TEST(TupleTest) {
+ }
+
+ Y_UNIT_TEST(TupleTest) {
std::tuple<int, double, bool, int> t{5, 3.14, true, 20};
- TString res;
-
- ForEach(t, TOverloaded{
+ TString res;
+
+ ForEach(t, TOverloaded{
[&](int val) { res += "(int) " + ToString(val) + ' '; },
[&](double val) { res += "(double) " + ToString(val) + ' '; },
[&](bool val) { res += "(bool) " + ToString(val) + ' '; },
});
-
+
UNIT_ASSERT_VALUES_EQUAL(res, "(int) 5 (double) 3.14 (bool) 1 (int) 20 ");
- }
+ }
Y_UNIT_TEST(ImplicitConversionsTest) {
using TTestVariant = std::variant<int, double, char>;
@@ -79,4 +79,4 @@ Y_UNIT_TEST_SUITE(TOverloadedTest) {
UNIT_ASSERT_VALUES_EQUAL(matchAsDouble(TTestVariant{12345}), 12345.0);
UNIT_ASSERT_VALUES_EQUAL(matchAsDouble(TTestVariant{'X'}), 88.0);
}
-}
+}
diff --git a/util/generic/ptr_ut.cpp b/util/generic/ptr_ut.cpp
index 29bee493b5..c2dcff23f6 100644
--- a/util/generic/ptr_ut.cpp
+++ b/util/generic/ptr_ut.cpp
@@ -204,9 +204,9 @@ void TPointerTest::TestMakeHolder() {
{
struct TRec {
int X, Y;
- TRec(int x, int y)
- : X(x)
- , Y(y)
+ TRec(int x, int y)
+ : X(x)
+ , Y(y)
{
}
};
diff --git a/util/generic/serialized_enum_ut.cpp b/util/generic/serialized_enum_ut.cpp
index 6420f83c27..3a94e1d471 100644
--- a/util/generic/serialized_enum_ut.cpp
+++ b/util/generic/serialized_enum_ut.cpp
@@ -20,7 +20,7 @@ Y_UNIT_TEST_SUITE(TestSerializedEnum) {
enum EEmpty {
};
- UNIT_ASSERT_C((TTypeList<int, unsigned>::THave<typename TSelectEnumRepresentationType<EEmpty>::TType>::value), "empty enum using signed or unsigned integer underlying type");
+ UNIT_ASSERT_C((TTypeList<int, unsigned>::THave<typename TSelectEnumRepresentationType<EEmpty>::TType>::value), "empty enum using signed or unsigned integer underlying type");
using TRepresentationTypeList = TTypeList<int, unsigned, long long, unsigned long long>;
@@ -29,22 +29,22 @@ Y_UNIT_TEST_SUITE(TestSerializedEnum) {
Two = 2,
Five = 5,
};
- UNIT_ASSERT(TRepresentationTypeList::THave<typename TSelectEnumRepresentationType<ERegular>::TType>::value);
+ UNIT_ASSERT(TRepresentationTypeList::THave<typename TSelectEnumRepresentationType<ERegular>::TType>::value);
enum class ESmall: unsigned char {
Six = 6,
};
- UNIT_ASSERT(TRepresentationTypeList::THave<typename TSelectEnumRepresentationType<ESmall>::TType>::value);
+ UNIT_ASSERT(TRepresentationTypeList::THave<typename TSelectEnumRepresentationType<ESmall>::TType>::value);
enum class EHugeUnsigned: ui64 {
Value = 0,
};
- UNIT_ASSERT(TRepresentationTypeList::THave<typename TSelectEnumRepresentationType<EHugeUnsigned>::TType>::value);
+ UNIT_ASSERT(TRepresentationTypeList::THave<typename TSelectEnumRepresentationType<EHugeUnsigned>::TType>::value);
enum class EHugeSigned: i64 {
Value = -2,
};
- UNIT_ASSERT(TRepresentationTypeList::THave<typename TSelectEnumRepresentationType<EHugeSigned>::TType>::value);
+ UNIT_ASSERT(TRepresentationTypeList::THave<typename TSelectEnumRepresentationType<EHugeSigned>::TType>::value);
}
Y_UNIT_TEST(MappedArrayView) {
diff --git a/util/generic/strbase.h b/util/generic/strbase.h
index 56c974cca9..ab39fc7537 100644
--- a/util/generic/strbase.h
+++ b/util/generic/strbase.h
@@ -556,7 +556,7 @@ public:
return CopyImpl(pc, n, pos);
}
- inline size_t copy(TCharType* pc, size_t n) const noexcept {
+ inline size_t copy(TCharType* pc, size_t n) const noexcept {
return CopyImpl(pc, n, 0);
}
diff --git a/util/generic/typelist.h b/util/generic/typelist.h
index 06eaded7ab..5ce26ab97c 100644
--- a/util/generic/typelist.h
+++ b/util/generic/typelist.h
@@ -2,8 +2,8 @@
#include <util/system/types.h>
-#include <util/generic/typetraits.h>
-
+#include <util/generic/typetraits.h>
+
#include <type_traits>
template <class... R>
@@ -12,25 +12,25 @@ struct TTypeList;
namespace NTL {
template <unsigned N, typename TL>
struct TGetImpl {
- using type = typename TGetImpl<N - 1, typename TL::TTail>::type;
+ using type = typename TGetImpl<N - 1, typename TL::TTail>::type;
};
template <typename TL>
struct TGetImpl<0u, TL> {
- using type = typename TL::THead;
+ using type = typename TL::THead;
};
}
template <>
struct TTypeList<> {
- static constexpr size_t Length = 0;
+ static constexpr size_t Length = 0;
- template <class>
- using THave = std::false_type;
+ template <class>
+ using THave = std::false_type;
template <template <class> class P>
struct TSelectBy {
- using type = TTypeList<>;
+ using type = TTypeList<>;
};
};
@@ -41,17 +41,17 @@ struct TTypeList<H, R...> {
using THead = H;
using TTail = TTypeList<R...>;
- static constexpr size_t Length = 1 + sizeof...(R);
+ static constexpr size_t Length = 1 + sizeof...(R);
template <class V>
- using THave = TDisjunction<std::is_same<H, V>, typename TTail::template THave<V>>;
+ using THave = TDisjunction<std::is_same<H, V>, typename TTail::template THave<V>>;
template <unsigned N>
- using TGet = typename ::NTL::TGetImpl<N, TTypeList<H, R...>>::type;
+ using TGet = typename ::NTL::TGetImpl<N, TTypeList<H, R...>>::type;
template <template <class> class P>
struct TSelectBy {
- using type = std::conditional_t<P<THead>::value, THead, typename TTail::template TSelectBy<P>::type>;
+ using type = std::conditional_t<P<THead>::value, THead, typename TTail::template TSelectBy<P>::type>;
};
};
@@ -60,11 +60,11 @@ template <class T>
struct TTypeList<T, TNone>: public TTypeList<T> {
};
-using TCommonSignedInts = TTypeList<signed char, signed short, signed int, signed long, signed long long>;
-using TCommonUnsignedInts = TTypeList<unsigned char, unsigned short, unsigned int, unsigned long, unsigned long long, bool>;
-using TFixedWidthSignedInts = TTypeList<i8, i16, i32, i64>;
-using TFixedWidthUnsignedInts = TTypeList<ui8, ui16, ui32, ui64>;
-using TFloats = TTypeList<float, double, long double>;
+using TCommonSignedInts = TTypeList<signed char, signed short, signed int, signed long, signed long long>;
+using TCommonUnsignedInts = TTypeList<unsigned char, unsigned short, unsigned int, unsigned long, unsigned long long, bool>;
+using TFixedWidthSignedInts = TTypeList<i8, i16, i32, i64>;
+using TFixedWidthUnsignedInts = TTypeList<ui8, ui16, ui32, ui64>;
+using TFloats = TTypeList<float, double, long double>;
namespace NTL {
template <class T1, class T2>
@@ -72,19 +72,19 @@ namespace NTL {
template <class... R1, class... R2>
struct TConcat<TTypeList<R1...>, TTypeList<R2...>> {
- using type = TTypeList<R1..., R2...>;
+ using type = TTypeList<R1..., R2...>;
};
template <bool isSigned, class T, class TS, class TU>
struct TTypeSelectorBase {
- using TSignedInts = typename TConcat<TTypeList<T>, TS>::type;
+ using TSignedInts = typename TConcat<TTypeList<T>, TS>::type;
using TUnsignedInts = TU;
};
template <class T, class TS, class TU>
struct TTypeSelectorBase<false, T, TS, TU> {
using TSignedInts = TS;
- using TUnsignedInts = typename TConcat<TTypeList<T>, TU>::type;
+ using TUnsignedInts = typename TConcat<TTypeList<T>, TU>::type;
};
template <class T, class TS, class TU>
@@ -101,14 +101,14 @@ using TUnsignedInts = NTL::T2::TUnsignedInts;
template <unsigned sizeOf>
struct TSizeOfPredicate {
template <class T>
- using TResult = TBoolConstant<sizeof(T) == sizeOf>;
+ using TResult = TBoolConstant<sizeof(T) == sizeOf>;
};
-
-template <typename T>
-using TFixedWidthSignedInt = typename TFixedWidthSignedInts::template TSelectBy<TSizeOfPredicate<sizeof(T)>::template TResult>::type;
-
-template <typename T>
-using TFixedWidthUnsignedInt = typename TFixedWidthUnsignedInts::template TSelectBy<TSizeOfPredicate<sizeof(T)>::template TResult>::type;
+
+template <typename T>
+using TFixedWidthSignedInt = typename TFixedWidthSignedInts::template TSelectBy<TSizeOfPredicate<sizeof(T)>::template TResult>::type;
+
+template <typename T>
+using TFixedWidthUnsignedInt = typename TFixedWidthUnsignedInts::template TSelectBy<TSizeOfPredicate<sizeof(T)>::template TResult>::type;
template <typename T>
using TFixedWidthFloat = typename TFloats::template TSelectBy<TSizeOfPredicate<sizeof(T)>::template TResult>::type;
diff --git a/util/generic/typelist_ut.cpp b/util/generic/typelist_ut.cpp
index 4c674bf0cb..eeabfa97b1 100644
--- a/util/generic/typelist_ut.cpp
+++ b/util/generic/typelist_ut.cpp
@@ -34,11 +34,11 @@ public:
struct TC {};
void TestHave() {
using TListType = TTypeList<TA, TB*, const TC&>;
- UNIT_ASSERT(TListType::THave<TA>::value);
- UNIT_ASSERT(TListType::THave<TB*>::value);
- UNIT_ASSERT(!TListType::THave<TB>::value);
- UNIT_ASSERT(TListType::THave<const TC&>::value);
- UNIT_ASSERT(!TListType::THave<TC&>::value);
+ UNIT_ASSERT(TListType::THave<TA>::value);
+ UNIT_ASSERT(TListType::THave<TB*>::value);
+ UNIT_ASSERT(!TListType::THave<TB>::value);
+ UNIT_ASSERT(TListType::THave<const TC&>::value);
+ UNIT_ASSERT(!TListType::THave<TC&>::value);
}
template <class T>
@@ -55,7 +55,7 @@ public:
template <template <class...> class TT, class... R>
struct TIsNArgTemplate<TT<R...>>: std::true_type {};
-
+
template <class>
struct TAnyType: std::true_type {};
@@ -68,10 +68,10 @@ public:
void TestSelectBy() {
using TListType = TTypeList<TA, TB, TMyMap<TA*, TB>, TMyVector<TA>, TC>;
- UNIT_ASSERT_TYPES_EQUAL(TListType::TSelectBy<TAnyType>::type, TA);
- UNIT_ASSERT_TYPES_EQUAL(TListType::TSelectBy<TIs1ArgTemplate>::type, TMyVector<TA>);
+ UNIT_ASSERT_TYPES_EQUAL(TListType::TSelectBy<TAnyType>::type, TA);
+ UNIT_ASSERT_TYPES_EQUAL(TListType::TSelectBy<TIs1ArgTemplate>::type, TMyVector<TA>);
using TMyMapPTATB = TMyMap<TA*, TB>;
- UNIT_ASSERT_TYPES_EQUAL(TListType::TSelectBy<TIsNArgTemplate>::type, TMyMapPTATB);
+ UNIT_ASSERT_TYPES_EQUAL(TListType::TSelectBy<TIsNArgTemplate>::type, TMyMapPTATB);
}
void TestFloatList() {
diff --git a/util/generic/typetraits.h b/util/generic/typetraits.h
index a1c7fa35c2..d165bd1a06 100644
--- a/util/generic/typetraits.h
+++ b/util/generic/typetraits.h
@@ -9,74 +9,74 @@
#include <stlfwd>
#if _LIBCPP_STD_VER >= 17
-template <bool B>
+template <bool B>
using TBoolConstant = std::bool_constant<B>;
#else
template <bool B>
struct TBoolConstant: std::integral_constant<bool, B> {};
#endif
-
+
#if _LIBCPP_STD_VER >= 17
-template <class B>
+template <class B>
using TNegation = std::negation<B>;
#else
template <class B>
struct TNegation: ::TBoolConstant<!bool(B::value)> {};
#endif
-
-namespace NPrivate {
- template <class... Bs>
- constexpr bool ConjunctionImpl() {
+
+namespace NPrivate {
+ template <class... Bs>
+ constexpr bool ConjunctionImpl() {
bool bs[] = {(bool)Bs::value...};
- for (auto b : bs) {
- if (!b) {
- return false;
- }
- }
- return true;
- }
-
- template <class... Bs>
- constexpr bool DisjunctionImpl() {
+ for (auto b : bs) {
+ if (!b) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ template <class... Bs>
+ constexpr bool DisjunctionImpl() {
bool bs[] = {(bool)Bs::value...};
- for (auto b : bs) {
- if (b) {
- return true;
- }
- }
- return false;
- }
-}
-
+ for (auto b : bs) {
+ if (b) {
+ return true;
+ }
+ }
+ return false;
+ }
+}
+
#if _LIBCPP_STD_VER >= 17 && !defined(_MSC_VER)
// Disable std::conjunction for MSVC by analogy with std::disjunction.
-template <class... Bs>
+template <class... Bs>
using TConjunction = std::conjunction<Bs...>;
#else
template <class... Bs>
struct TConjunction: ::TBoolConstant<::NPrivate::ConjunctionImpl<Bs...>()> {};
#endif
-
+
#if _LIBCPP_STD_VER >= 17 && !defined(_MSC_VER)
// Disable std::disjunction for MSVC.
// It reduces build time (500 -> 20 seconds) and memory consumption (20 GB -> less than 1 GB)
// for some files (notably search/dssm_boosting/dssm_boosting_calcer.cpp).
-template <class... Bs>
+template <class... Bs>
using TDisjunction = std::disjunction<Bs...>;
#else
template <class... Bs>
struct TDisjunction: ::TBoolConstant<::NPrivate::DisjunctionImpl<Bs...>()> {};
#endif
-
+
#if _LIBCPP_STD_VER >= 17
template <class... Bs>
using TVoidT = std::void_t<Bs...>;
#else
-template <class...>
-using TVoidT = void;
+template <class...>
+using TVoidT = void;
#endif
-
-template <class T>
+
+template <class T>
struct TPodTraits {
enum {
IsPod = false
@@ -160,7 +160,7 @@ class TTypeTraits<void>: public TTypeTraitsBase<void> {};
: std::integral_constant<bool, TClassHas##name<T>::value> {}; \
template <class T> \
struct THas##name \
- : TBaseHas##name<T, std::is_class<T>::value || std::is_union<T>::value> {}
+ : TBaseHas##name<T, std::is_class<T>::value || std::is_union<T>::value> {}
#define Y_HAS_MEMBER_IMPL_1(name) Y_HAS_MEMBER_IMPL_2(name, name)
@@ -170,7 +170,7 @@ class TTypeTraits<void>: public TTypeTraitsBase<void> {};
* metaprogramming.
*
* Macro accept one or two parameters, when used with two parameters e.g. `Y_HAS_MEMBER(xyz, ABC)`
- * will define class `THasABC` with static member `value` of type bool. Usage with one parameter
+ * will define class `THasABC` with static member `value` of type bool. Usage with one parameter
* e.g. `Y_HAS_MEMBER(xyz)` will produce the same result as `Y_HAS_MEMBER(xyz, xyz)`.
*
* @code
@@ -179,13 +179,13 @@ class TTypeTraits<void>: public TTypeTraitsBase<void> {};
* Y_HAS_MEMBER(push_front, PushFront);
*
* template <typename T, typename U>
- * std::enable_if_t<THasPushFront<T>::value, void>
+ * std::enable_if_t<THasPushFront<T>::value, void>
* PushFront(T& container, const U value) {
* container.push_front(x);
* }
*
* template <typename T, typename U>
- * std::enable_if_t<!THasPushFront<T>::value, void>
+ * std::enable_if_t<!THasPushFront<T>::value, void>
* PushFront(T& container, const U value) {
* container.insert(container.begin(), x);
* }
@@ -207,7 +207,7 @@ class TTypeTraits<void>: public TTypeTraitsBase<void> {};
* metaprogramming.
*
* Macro accept one or two parameters, when used with two parameters e.g. `Y_HAS_SUBTYPE(xyz, ABC)`
- * will define class `THasABC` with static member `value` of type bool. Usage with one parameter
+ * will define class `THasABC` with static member `value` of type bool. Usage with one parameter
* e.g. `Y_HAS_SUBTYPE(xyz)` will produce the same result as `Y_HAS_SUBTYPE(xyz, xyz)`.
*
* @code
@@ -217,7 +217,7 @@ class TTypeTraits<void>: public TTypeTraitsBase<void> {};
*
* template <typename T>
* using TIsAssocCont = std::conditional_t<
- * THasFindMethod<T>::value && THasConstIterator<T>::value && THasKeyType<T>::value,
+ * THasFindMethod<T>::value && THasConstIterator<T>::value && THasKeyType<T>::value,
* std::true_type,
* std::false_type,
* >;
@@ -262,11 +262,11 @@ struct TIsPointerToConstMemberFunction<R (T::*)(Args..., ...) const&>: std::true
template <class R, class T, class... Args>
struct TIsPointerToConstMemberFunction<R (T::*)(Args..., ...) const&&>: std::true_type {
};
-
-template <template <class...> class T, class U>
+
+template <template <class...> class T, class U>
struct TIsSpecializationOf: std::false_type {};
-
-template <template <class...> class T, class... Ts>
+
+template <template <class...> class T, class... Ts>
struct TIsSpecializationOf<T, T<Ts...>>: std::true_type {};
/*
diff --git a/util/generic/typetraits_ut.cpp b/util/generic/typetraits_ut.cpp
index 24b7febc6f..e7571c75ec 100644
--- a/util/generic/typetraits_ut.cpp
+++ b/util/generic/typetraits_ut.cpp
@@ -2,9 +2,9 @@
#include <library/cpp/testing/unittest/registar.h>
-#include <vector>
-#include <tuple>
-
+#include <vector>
+#include <tuple>
+
namespace {
enum ETestEnum {
};
@@ -450,12 +450,12 @@ static_assert(std::is_same<i8, TFixedWidthSignedInt<ui8>>::value, "");
static_assert(std::is_same<i16, TFixedWidthSignedInt<ui16>>::value, "");
static_assert(std::is_same<i32, TFixedWidthSignedInt<ui32>>::value, "");
static_assert(std::is_same<i64, TFixedWidthSignedInt<ui64>>::value, "");
-
-// test for TIsSpecializationOf
-static_assert(TIsSpecializationOf<std::vector, std::vector<int>>::value, "");
-static_assert(TIsSpecializationOf<std::tuple, std::tuple<int, double, char>>::value, "");
-static_assert(!TIsSpecializationOf<std::vector, std::tuple<int, double, char>>::value, "");
-static_assert(!TIsSpecializationOf<std::pair, std::vector<int>>::value, "");
+
+// test for TIsSpecializationOf
+static_assert(TIsSpecializationOf<std::vector, std::vector<int>>::value, "");
+static_assert(TIsSpecializationOf<std::tuple, std::tuple<int, double, char>>::value, "");
+static_assert(!TIsSpecializationOf<std::vector, std::tuple<int, double, char>>::value, "");
+static_assert(!TIsSpecializationOf<std::pair, std::vector<int>>::value, "");
// test for TIsIterable
static_assert(TIsIterable<std::vector<int>>::value, "");
diff --git a/util/generic/utility.h b/util/generic/utility.h
index 75f63400d7..43b98eeafc 100644
--- a/util/generic/utility.h
+++ b/util/generic/utility.h
@@ -69,27 +69,27 @@ namespace NSwapCheck {
Y_HAS_MEMBER(swap);
Y_HAS_MEMBER(Swap);
- template <class T, class = void>
- struct TSwapSelector {
- static inline void Swap(T& l, T& r) noexcept(std::is_nothrow_move_constructible<T>::value&&
- std::is_nothrow_move_assignable<T>::value) {
- T tmp(std::move(l));
- l = std::move(r);
- r = std::move(tmp);
+ template <class T, class = void>
+ struct TSwapSelector {
+ static inline void Swap(T& l, T& r) noexcept(std::is_nothrow_move_constructible<T>::value&&
+ std::is_nothrow_move_assignable<T>::value) {
+ T tmp(std::move(l));
+ l = std::move(r);
+ r = std::move(tmp);
}
};
- template <class T>
- struct TSwapSelector<T, std::enable_if_t<THasSwap<T>::value>> {
- static inline void Swap(T& l, T& r) noexcept(noexcept(l.Swap(r))) {
- l.Swap(r);
+ template <class T>
+ struct TSwapSelector<T, std::enable_if_t<THasSwap<T>::value>> {
+ static inline void Swap(T& l, T& r) noexcept(noexcept(l.Swap(r))) {
+ l.Swap(r);
}
};
- template <class T>
- struct TSwapSelector<T, std::enable_if_t<THasswap<T>::value && !THasSwap<T>::value>> {
- static inline void Swap(T& l, T& r) noexcept(noexcept(l.swap(r))) {
- l.swap(r);
+ template <class T>
+ struct TSwapSelector<T, std::enable_if_t<THasswap<T>::value && !THasSwap<T>::value>> {
+ static inline void Swap(T& l, T& r) noexcept(noexcept(l.swap(r))) {
+ l.swap(r);
}
};
}
@@ -98,7 +98,7 @@ namespace NSwapCheck {
* DoSwap better than ::Swap in member functions...
*/
template <class T>
-static inline void DoSwap(T& l, T& r) noexcept(noexcept(NSwapCheck::TSwapSelector<T>::Swap(l, r))) {
+static inline void DoSwap(T& l, T& r) noexcept(noexcept(NSwapCheck::TSwapSelector<T>::Swap(l, r))) {
NSwapCheck::TSwapSelector<T>::Swap(l, r);
}
diff --git a/util/generic/variant.h b/util/generic/variant.h
index 9313f3cfa8..749fc75090 100644
--- a/util/generic/variant.h
+++ b/util/generic/variant.h
@@ -13,11 +13,11 @@ public:
v.valueless_by_exception() ? 0 : std::visit([](const auto& value) { return ComputeHash(value); }, v));
}
};
-
-template <>
+
+template <>
struct THash<std::monostate> {
-public:
+public:
constexpr size_t operator()(std::monostate) const noexcept {
return 1;
}
-};
+};