diff options
author | sharpeye <sharpeye@yandex-team.ru> | 2022-02-10 16:49:16 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:49:16 +0300 |
commit | 5ba59e58ca0ed3be83efee8a12c92725dfc5f051 (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /util/generic | |
parent | 9a407601824f50398148409237b90de3f95b5ae3 (diff) | |
download | ydb-5ba59e58ca0ed3be83efee8a12c92725dfc5f051.tar.gz |
Restoring authorship annotation for <sharpeye@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util/generic')
-rw-r--r-- | util/generic/scope.h | 42 | ||||
-rw-r--r-- | util/generic/scope_ut.cpp | 36 |
2 files changed, 39 insertions, 39 deletions
diff --git a/util/generic/scope.h b/util/generic/scope.h index 0d7a3b13d3..b2c33af61e 100644 --- a/util/generic/scope.h +++ b/util/generic/scope.h @@ -1,43 +1,43 @@ #pragma once -#include <util/system/compiler.h> +#include <util/system/compiler.h> #include <util/system/defaults.h> - -#include <utility> -namespace NPrivate { - template <typename F> - class TScopeGuard { - public: - TScopeGuard(const F& function) +#include <utility> + +namespace NPrivate { + template <typename F> + class TScopeGuard { + public: + TScopeGuard(const F& function) : Function_{function} { } - TScopeGuard(F&& function) + TScopeGuard(F&& function) : Function_{std::move(function)} { } - TScopeGuard(TScopeGuard&&) = default; - TScopeGuard(const TScopeGuard&) = default; - - ~TScopeGuard() { - Function_(); - } - + TScopeGuard(TScopeGuard&&) = default; + TScopeGuard(const TScopeGuard&) = default; + + ~TScopeGuard() { + Function_(); + } + private: F Function_; }; - struct TMakeGuardHelper { - template <class F> + struct TMakeGuardHelper { + template <class F> TScopeGuard<F> operator|(F&& function) const { - return std::forward<F>(function); - } + return std::forward<F>(function); + } }; } - + // \brief `Y_SCOPE_EXIT(captures) { body };` // // General implementaion of RAII idiom (resource acquisition is initialization). Executes diff --git a/util/generic/scope_ut.cpp b/util/generic/scope_ut.cpp index 62547f0b1d..bdb434d487 100644 --- a/util/generic/scope_ut.cpp +++ b/util/generic/scope_ut.cpp @@ -8,30 +8,30 @@ Y_UNIT_TEST_SUITE(ScopeToolsTest) { int i = 0; { - Y_SCOPE_EXIT(&i) { - i = i * 2; - }; - - Y_SCOPE_EXIT(&i) { - i = i + 1; - }; + Y_SCOPE_EXIT(&i) { + i = i * 2; + }; + + Y_SCOPE_EXIT(&i) { + i = i + 1; + }; } UNIT_ASSERT_VALUES_EQUAL(2, i); } - + Y_UNIT_TEST(OnScopeExitMoveTest) { THolder<int> i{new int{10}}; - int p = 0; - - { - Y_SCOPE_EXIT(i = std::move(i), &p) { - p = *i * 2; - }; - } - - UNIT_ASSERT_VALUES_EQUAL(20, p); - } + int p = 0; + + { + Y_SCOPE_EXIT(i = std::move(i), &p) { + p = *i * 2; + }; + } + + UNIT_ASSERT_VALUES_EQUAL(20, p); + } Y_UNIT_TEST(TestDefer) { int i = 0; |