aboutsummaryrefslogtreecommitdiffstats
path: root/util
diff options
context:
space:
mode:
authorkzhagorina <kzhagorina@yandex-team.ru>2022-02-10 16:52:08 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:52:08 +0300
commitd3adae76593c2a6b659badc21bfa262bec99a298 (patch)
treeab7fbbf3253d4c0e2793218f09378908beb025fb /util
parentc39389ed2a289ad2298240c5f04d6a17fdac57d9 (diff)
downloadydb-d3adae76593c2a6b659badc21bfa262bec99a298.tar.gz
Restoring authorship annotation for <kzhagorina@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util')
-rw-r--r--util/generic/lazy_value.h22
-rw-r--r--util/generic/lazy_value_ut.cpp118
2 files changed, 70 insertions, 70 deletions
diff --git a/util/generic/lazy_value.h b/util/generic/lazy_value.h
index 8c65dafb92..3c720f76b5 100644
--- a/util/generic/lazy_value.h
+++ b/util/generic/lazy_value.h
@@ -4,11 +4,11 @@
#include "function.h"
template <class T>
-class TLazyValueBase {
+class TLazyValueBase {
public:
using TInitializer = std::function<T()>;
- TLazyValueBase() = default;
+ TLazyValueBase() = default;
TLazyValueBase(TInitializer initializer)
: Initializer(std::move(initializer))
@@ -48,18 +48,18 @@ private:
TInitializer Initializer;
};
-// we need this to get implicit construction TLazyValue from lambda
-// and save default copy constructor and operator= for type TLazyValue
-template <class T>
+// we need this to get implicit construction TLazyValue from lambda
+// and save default copy constructor and operator= for type TLazyValue
+template <class T>
class TLazyValue: public TLazyValueBase<T> {
-public:
- template <typename... TArgs>
- TLazyValue(TArgs&&... args)
- : TLazyValueBase<T>(std::forward<TArgs>(args)...)
+public:
+ template <typename... TArgs>
+ TLazyValue(TArgs&&... args)
+ : TLazyValueBase<T>(std::forward<TArgs>(args)...)
{
}
-};
-
+};
+
template <typename F>
TLazyValue<TFunctionResult<F>> MakeLazy(F&& f) {
return {std::forward<F>(f)};
diff --git a/util/generic/lazy_value_ut.cpp b/util/generic/lazy_value_ut.cpp
index e478ecf3d8..f6135880c3 100644
--- a/util/generic/lazy_value_ut.cpp
+++ b/util/generic/lazy_value_ut.cpp
@@ -17,31 +17,31 @@ Y_UNIT_TEST_SUITE(TLazyValueTestSuite) {
TLazyValue<int> value2 = []() { return 5; };
- TLazyValue<int> notInitialized{};
-
- TLazyValue<int> copy1(value1);
-
- copy1 = value2;
- }
-
+ TLazyValue<int> notInitialized{};
+
+ TLazyValue<int> copy1(value1);
+
+ copy1 = value2;
+ }
+
Y_UNIT_TEST(TestLazyValueCopy) {
TLazyValue<int> value([]() { return 5; });
- UNIT_ASSERT(!value);
-
- TLazyValue<int> emptyCopy = value;
- UNIT_ASSERT(!emptyCopy);
-
- UNIT_ASSERT_EQUAL(*emptyCopy, 5);
- UNIT_ASSERT(emptyCopy);
- UNIT_ASSERT(!value);
-
- UNIT_ASSERT_EQUAL(*value, 5);
-
- TLazyValue<int> notEmptyCopy = value;
- UNIT_ASSERT(notEmptyCopy);
+ UNIT_ASSERT(!value);
+
+ TLazyValue<int> emptyCopy = value;
+ UNIT_ASSERT(!emptyCopy);
+
+ UNIT_ASSERT_EQUAL(*emptyCopy, 5);
+ UNIT_ASSERT(emptyCopy);
+ UNIT_ASSERT(!value);
+
+ UNIT_ASSERT_EQUAL(*value, 5);
+
+ TLazyValue<int> notEmptyCopy = value;
+ UNIT_ASSERT(notEmptyCopy);
UNIT_ASSERT_EQUAL(*notEmptyCopy, 5);
- }
-
+ }
+
struct TCopyCounter {
TCopyCounter(size_t& numCopies)
: NumCopies(&numCopies)
@@ -89,10 +89,10 @@ Y_UNIT_TEST_SUITE(TLazyValueTestSuite) {
UNIT_ASSERT_EQUAL(numCopies, 1);
}
- class TValueProvider {
+ class TValueProvider {
public:
- static size_t CountParseDataCalled;
-
+ static size_t CountParseDataCalled;
+
TValueProvider()
: Data_([&] { return this->ParseData(); })
{
@@ -101,18 +101,18 @@ Y_UNIT_TEST_SUITE(TLazyValueTestSuite) {
const TString& GetData() const {
return *Data_;
}
-
- private:
+
+ private:
TLazyValue<TString> Data_;
-
- TString ParseData() {
- CountParseDataCalled++;
- return "hi";
- }
+
+ TString ParseData() {
+ CountParseDataCalled++;
+ return "hi";
+ }
};
- size_t TValueProvider::CountParseDataCalled = 0;
-
+ size_t TValueProvider::CountParseDataCalled = 0;
+
Y_UNIT_TEST(TestValueProvider) {
TValueProvider provider;
@@ -120,32 +120,32 @@ Y_UNIT_TEST_SUITE(TLazyValueTestSuite) {
}
Y_UNIT_TEST(TestValueProviderCopy) {
- TValueProvider provider;
- provider.GetData();
- const auto countParsed = TValueProvider::CountParseDataCalled;
- provider.GetData();
- UNIT_ASSERT_EQUAL(countParsed, TValueProvider::CountParseDataCalled);
-
- TValueProvider providerCopy;
- providerCopy = provider;
- providerCopy.GetData();
- UNIT_ASSERT_EQUAL(countParsed, TValueProvider::CountParseDataCalled);
- }
-
+ TValueProvider provider;
+ provider.GetData();
+ const auto countParsed = TValueProvider::CountParseDataCalled;
+ provider.GetData();
+ UNIT_ASSERT_EQUAL(countParsed, TValueProvider::CountParseDataCalled);
+
+ TValueProvider providerCopy;
+ providerCopy = provider;
+ providerCopy.GetData();
+ UNIT_ASSERT_EQUAL(countParsed, TValueProvider::CountParseDataCalled);
+ }
+
Y_UNIT_TEST(TestEmptyProviderCopy) {
- TValueProvider provider;
- TValueProvider copy(provider);
-
- const auto countParsed = TValueProvider::CountParseDataCalled;
- provider.GetData();
- UNIT_ASSERT_EQUAL(countParsed + 1, TValueProvider::CountParseDataCalled);
- copy.GetData();
- UNIT_ASSERT_EQUAL(countParsed + 2, TValueProvider::CountParseDataCalled);
- const TValueProvider notEmptyCopy(copy);
- notEmptyCopy.GetData();
- UNIT_ASSERT_EQUAL(countParsed + 2, TValueProvider::CountParseDataCalled);
- }
-
+ TValueProvider provider;
+ TValueProvider copy(provider);
+
+ const auto countParsed = TValueProvider::CountParseDataCalled;
+ provider.GetData();
+ UNIT_ASSERT_EQUAL(countParsed + 1, TValueProvider::CountParseDataCalled);
+ copy.GetData();
+ UNIT_ASSERT_EQUAL(countParsed + 2, TValueProvider::CountParseDataCalled);
+ const TValueProvider notEmptyCopy(copy);
+ notEmptyCopy.GetData();
+ UNIT_ASSERT_EQUAL(countParsed + 2, TValueProvider::CountParseDataCalled);
+ }
+
Y_UNIT_TEST(TestMakeLazy) {
auto lv = MakeLazy([] {
return 100500;