aboutsummaryrefslogtreecommitdiffstats
path: root/util/generic
diff options
context:
space:
mode:
authorkartynnik <kartynnik@yandex-team.ru>2022-02-10 16:48:07 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:48:07 +0300
commitdf6128370874866447314ec18d8e67fc7bde40b4 (patch)
treeb222e5ac2e2e98872661c51ccceee5da0d291e13 /util/generic
parentca2a705e6e39e85df30054d7e806e572de9cfe23 (diff)
downloadydb-df6128370874866447314ec18d8e67fc7bde40b4.tar.gz
Restoring authorship annotation for <kartynnik@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'util/generic')
-rw-r--r--util/generic/algorithm.h42
-rw-r--r--util/generic/algorithm_ut.cpp6
-rw-r--r--util/generic/iterator.h6
-rw-r--r--util/generic/iterator_ut.cpp10
-rw-r--r--util/generic/va_args.cpp16
-rw-r--r--util/generic/va_args.h12
-rwxr-xr-xutil/generic/va_args_gen.py56
-rw-r--r--util/generic/va_args_ut.cpp22
8 files changed, 85 insertions, 85 deletions
diff --git a/util/generic/algorithm.h b/util/generic/algorithm.h
index ec8c0e9fae..badfb88993 100644
--- a/util/generic/algorithm.h
+++ b/util/generic/algorithm.h
@@ -34,35 +34,35 @@ namespace NPrivate {
}
template <class T>
-static inline void Sort(T f, T l) {
+static inline void Sort(T f, T l) {
std::sort(f, l);
}
template <class T, class C>
-static inline void Sort(T f, T l, C c) {
+static inline void Sort(T f, T l, C c) {
std::sort(f, l, c);
}
-template <class TContainer>
-static inline void Sort(TContainer& container) {
- Sort(container.begin(), container.end());
-}
-
-template <class TContainer, typename TCompare>
-static inline void Sort(TContainer& container, TCompare compare) {
- Sort(container.begin(), container.end(), compare);
-}
-
-template <class TIterator, typename TGetKey>
-static inline void SortBy(TIterator begin, TIterator end, const TGetKey& getKey) {
+template <class TContainer>
+static inline void Sort(TContainer& container) {
+ Sort(container.begin(), container.end());
+}
+
+template <class TContainer, typename TCompare>
+static inline void Sort(TContainer& container, TCompare compare) {
+ Sort(container.begin(), container.end(), compare);
+}
+
+template <class TIterator, typename TGetKey>
+static inline void SortBy(TIterator begin, TIterator end, const TGetKey& getKey) {
Sort(begin, end, [&](auto&& left, auto&& right) { return getKey(left) < getKey(right); });
-}
-
-template <class TContainer, typename TGetKey>
-static inline void SortBy(TContainer& container, const TGetKey& getKey) {
- SortBy(container.begin(), container.end(), getKey);
-}
-
+}
+
+template <class TContainer, typename TGetKey>
+static inline void SortBy(TContainer& container, const TGetKey& getKey) {
+ SortBy(container.begin(), container.end(), getKey);
+}
+
template <class T>
static inline void StableSort(T f, T l) {
std::stable_sort(f, l);
diff --git a/util/generic/algorithm_ut.cpp b/util/generic/algorithm_ut.cpp
index e281def406..8d732fcc0c 100644
--- a/util/generic/algorithm_ut.cpp
+++ b/util/generic/algorithm_ut.cpp
@@ -430,7 +430,7 @@ Y_UNIT_TEST_SUITE(TAlgorithm) {
UNIT_ASSERT_VALUES_EQUAL(IsSorted(v2.begin(), v2.end(), TLess<int>()), false);
UNIT_ASSERT_VALUES_EQUAL(IsSorted(v2.begin(), v2.end(), TGreater<int>()), false);
}
-
+
Y_UNIT_TEST(IsSortedByTest) {
TVector<int> v0;
UNIT_ASSERT_VALUES_EQUAL(IsSortedBy(v0.begin(), v0.end(), std::negate<int>()), true);
@@ -505,8 +505,8 @@ Y_UNIT_TEST_SUITE(TAlgorithm) {
TVector<int> collection = {10, 2, 7};
SortBy(collection, [](int x) { return -x; });
TVector<int> expected = {10, 7, 2};
- UNIT_ASSERT_VALUES_EQUAL(collection, expected);
- }
+ UNIT_ASSERT_VALUES_EQUAL(collection, expected);
+ }
Y_UNIT_TEST(StableSortByTest) {
TVector<int> collection = {404, 101, 106, 203, 102, 205, 401};
diff --git a/util/generic/iterator.h b/util/generic/iterator.h
index 71a375a550..19e9d20976 100644
--- a/util/generic/iterator.h
+++ b/util/generic/iterator.h
@@ -127,13 +127,13 @@ public:
return TIterator();
}
};
-
+
/**
* Transform given reverse iterator into forward iterator pointing to the same element.
*
* @see http://stackoverflow.com/a/1830240
*/
-template <class TIterator>
+template <class TIterator>
auto ToForwardIterator(TIterator iter) {
return std::next(iter).base();
-}
+}
diff --git a/util/generic/iterator_ut.cpp b/util/generic/iterator_ut.cpp
index 1694c59b9c..00be19e10e 100644
--- a/util/generic/iterator_ut.cpp
+++ b/util/generic/iterator_ut.cpp
@@ -1,14 +1,14 @@
-#include "iterator.h"
-
+#include "iterator.h"
+
#include <library/cpp/testing/unittest/registar.h>
-
+
Y_UNIT_TEST_SUITE(TIterator) {
Y_UNIT_TEST(ToForwardIteratorTest) {
TVector<int> x = {1, 2};
UNIT_ASSERT_VALUES_EQUAL(*std::prev(x.end()), *ToForwardIterator(x.rbegin()));
UNIT_ASSERT_VALUES_EQUAL(*ToForwardIterator(std::prev(x.rend())), *x.begin());
- }
-}
+ }
+}
Y_UNIT_TEST_SUITE(TInputRangeAdaptor) {
class TSquaresGenerator: public TInputRangeAdaptor<TSquaresGenerator> {
diff --git a/util/generic/va_args.cpp b/util/generic/va_args.cpp
index dd8c18ea6c..2266d05a0d 100644
--- a/util/generic/va_args.cpp
+++ b/util/generic/va_args.cpp
@@ -1,15 +1,15 @@
-#include "va_args.h"
-
-// Test that it compiles
-#define __DUMMY__(x)
+#include "va_args.h"
+
+// Test that it compiles
+#define __DUMMY__(x)
Y_MAP_ARGS(__DUMMY__, 1, 2, 3);
-#define __DUMMY_LAST__(x)
+#define __DUMMY_LAST__(x)
Y_MAP_ARGS_WITH_LAST(__DUMMY__, __DUMMY_LAST__, 1, 2, 3);
#undef __DUMMY_LAST__
#undef __DUMMY__
-
-#define __MULTI_DUMMY__(x, y)
-#define __MULTI_DUMMY_PROXY__(x) __MULTI_DUMMY__ x
+
+#define __MULTI_DUMMY__(x, y)
+#define __MULTI_DUMMY_PROXY__(x) __MULTI_DUMMY__ x
Y_MAP_ARGS(__MULTI_DUMMY_PROXY__, (1, 2), (3, 4));
#undef __MULTI_DUMMY_PROXY__
#undef __MULTI_DUMMY__
diff --git a/util/generic/va_args.h b/util/generic/va_args.h
index 8680520c72..33498d47ed 100644
--- a/util/generic/va_args.h
+++ b/util/generic/va_args.h
@@ -1,9 +1,9 @@
-#pragma once
-
+#pragma once
+
/// @file va_args.h
///
/// Some handy macros for preprocessor metaprogramming.
-
+
// NOTE: this file has been generated with "./va_args_gen.py", do not edit -- use the generator instead
// DO_NOT_STYLE
@@ -17,14 +17,14 @@
* See http://stackoverflow.com/questions/5134523/msvc-doesnt-expand-va-args-correctly
*/
#define Y_PASS_VA_ARGS(x) x
-
+
/**
* Count number of arguments in `__VA_ARGS__`.
* Doesn't work with empty arguments list.
*/
#define Y_COUNT_ARGS(...) Y_PASS_VA_ARGS(__Y_COUNT_ARGS(__VA_ARGS__, 50, 49, 48, 47, 46, 45, 44, 43, 42, 41, 40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0))
#define __Y_COUNT_ARGS(_50, _49, _48, _47, _46, _45, _44, _43, _42, _41, _40, _39, _38, _37, _36, _35, _34, _33, _32, _31, _30, _29, _28, _27, _26, _25, _24, _23, _22, _21, _20, _19, _18, _17, _16, _15, _14, _13, _12, _11, _10, _9, _8, _7, _6, _5, _4, _3, _2, _1, N, ...) N
-
+
/**
* Get the i-th element from `__VA_ARGS__`.
*/
@@ -80,7 +80,7 @@
#define __Y_GET_ARG_48(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, ...) _48
#define __Y_GET_ARG_49(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, ...) _49
#define __Y_GET_ARG_50(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, ...) _50
-
+
/**
* Expands a macro for each of the variable arguments.
* Doesn't work with empty arguments list.
diff --git a/util/generic/va_args_gen.py b/util/generic/va_args_gen.py
index b7d3537bae..232b53fca6 100755
--- a/util/generic/va_args_gen.py
+++ b/util/generic/va_args_gen.py
@@ -1,19 +1,19 @@
-#!/usr/bin/env python
+#!/usr/bin/env python
"""
Generates some handy macros for preprocessor metaprogramming.
-
+
"""
from __future__ import print_function
-import sys
+import sys
import textwrap
-
+
if sys.version_info >= (3, 0, 0):
xrange = range
-
-def generate(limit):
+
+def generate(limit):
print('#pragma once')
print(textwrap.dedent('''
/// @file va_args.h
@@ -28,7 +28,7 @@ def generate(limit):
print('')
print('#include <util/system/defaults.h>')
print('')
-
+
pass_va_args()
count(limit)
get_elem(limit)
@@ -39,8 +39,8 @@ def generate(limit):
all_but_last(limit)
last(limit)
impl_dispatcher()
-
-
+
+
def pass_va_args():
print(textwrap.dedent('''
/**
@@ -51,8 +51,8 @@ def pass_va_args():
*/
'''.rstrip()))
print('#define Y_PASS_VA_ARGS(x) x')
-
-
+
+
def count(limit):
print(textwrap.dedent('''
/**
@@ -66,7 +66,7 @@ def count(limit):
'__Y_COUNT_ARGS(__VA_ARGS__, {}))'.format(numbers))
print('#define __Y_COUNT_ARGS({}, N, ...) N'.format(u_numbers))
-
+
def get_elem(limit):
print(textwrap.dedent('''
/**
@@ -78,8 +78,8 @@ def get_elem(limit):
for i in xrange(0, limit + 1):
args = ', '.join(map('_{}'.format, xrange(i + 1)))
print('#define __Y_GET_ARG_{}({}, ...) _{}'.format(i, args, i))
-
-
+
+
def map_args(limit):
print(textwrap.dedent('''
/**
@@ -94,8 +94,8 @@ def map_args(limit):
for i in xrange(2, limit + 1):
print('#define __Y_MAP_ARGS_{}(ACTION, x, ...) ACTION(x) Y_PASS_VA_ARGS(__Y_MAP_ARGS_{}('
'ACTION, __VA_ARGS__))'.format(i, i - 1))
-
-
+
+
def map_args_n(limit):
print(textwrap.dedent('''
/**
@@ -128,8 +128,8 @@ def map_args_with_last(limit):
for i in xrange(2, limit + 1):
print('#define __Y_MAP_ARGS_WITH_LAST_{}(ACTION, LAST_ACTION, x, ...) ACTION(x) Y_PASS_VA_ARGS('
'__Y_MAP_ARGS_WITH_LAST_{}(ACTION, LAST_ACTION, __VA_ARGS__))'.format(i, i - 1))
-
-
+
+
def map_args_with_last_n(limit):
print(textwrap.dedent('''
/**
@@ -197,15 +197,15 @@ def impl_dispatcher():
print('/// }@')
-def main():
- if len(sys.argv) > 2:
+def main():
+ if len(sys.argv) > 2:
sys.stderr.write('Usage: {} [limit=50]\n'.format(sys.argv[0]))
- sys.exit(1)
+ sys.exit(1)
limit = 50
- if len(sys.argv) == 2:
- limit = int(sys.argv[1])
- generate(limit)
-
-
-if __name__ == '__main__':
- main()
+ if len(sys.argv) == 2:
+ limit = int(sys.argv[1])
+ generate(limit)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/util/generic/va_args_ut.cpp b/util/generic/va_args_ut.cpp
index 79ad45980b..a9c96a0f55 100644
--- a/util/generic/va_args_ut.cpp
+++ b/util/generic/va_args_ut.cpp
@@ -1,21 +1,21 @@
-#include "va_args.h"
-
+#include "va_args.h"
+
#include <library/cpp/testing/unittest/registar.h>
-
+
Y_UNIT_TEST_SUITE(TMacroVarargMapTest) {
Y_UNIT_TEST(TestMapArgs) {
static const char COMBINED[] = Y_MAP_ARGS(Y_STRINGIZE, 1, 2, 3);
- UNIT_ASSERT_STRINGS_EQUAL(COMBINED, "123");
- }
-
+ UNIT_ASSERT_STRINGS_EQUAL(COMBINED, "123");
+ }
+
Y_UNIT_TEST(TestMapArgsWithLast) {
-#define ADD(x) x +
-#define ID(x) x
+#define ADD(x) x +
+#define ID(x) x
static const int SUM = Y_MAP_ARGS_WITH_LAST(ADD, ID, 1, 2, 3, 4 + 5);
- UNIT_ASSERT_VALUES_EQUAL(SUM, 1 + 2 + 3 + 4 + 5);
+ UNIT_ASSERT_VALUES_EQUAL(SUM, 1 + 2 + 3 + 4 + 5);
#undef ADD
#undef ID
- }
+ }
Y_UNIT_TEST(TestMapArgsN) {
#define MAP_ARG(INDEX, X) Y_STRINGIZE(X)
@@ -40,7 +40,7 @@ Y_UNIT_TEST_SUITE(TMacroVarargMapTest) {
#undef ADD_ARG
#undef ID_ARG
}
-}
+}
Y_UNIT_TEST_SUITE(TestVaArgs) {
Y_UNIT_TEST(Count) {