diff options
author | pechatnov <pechatnov@yandex-team.ru> | 2022-02-10 16:48:57 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:48:57 +0300 |
commit | 132a3640fac343164b858d0a914e020a848a2848 (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/iterator/functools.h | |
parent | 8e9b2f8bbf4a2320f539eef5b85555f42c065425 (diff) | |
download | ydb-132a3640fac343164b858d0a914e020a848a2848.tar.gz |
Restoring authorship annotation for <pechatnov@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/iterator/functools.h')
-rw-r--r-- | library/cpp/iterator/functools.h | 114 |
1 files changed, 57 insertions, 57 deletions
diff --git a/library/cpp/iterator/functools.h b/library/cpp/iterator/functools.h index 3a2548292c..57a0d66373 100644 --- a/library/cpp/iterator/functools.h +++ b/library/cpp/iterator/functools.h @@ -1,57 +1,57 @@ -#pragma once - -#include "cartesian_product.h" -#include "concatenate.h" -#include "enumerate.h" -#include "filtering.h" -#include "mapped.h" -#include "zip.h" - -#include <util/generic/adaptor.h> -#include <util/generic/xrange.h> - -#include <tuple> -#include <algorithm> - - -namespace NFuncTools { - using ::Enumerate; - using ::Reversed; - using ::Zip; - using ::Concatenate; - using ::CartesianProduct; - - template <typename TValue> - auto Range(TValue from, TValue to, TValue step) { - return xrange(from, to, step); - } - - template <typename TValue> - auto Range(TValue from, TValue to) { - return xrange(from, to); - } - - template <typename TValue> - auto Range(TValue to) { - return xrange(to); - } - - //! Usage: for (i32 x : Map([](i32 x) { return x * x; }, a)) {...} - template <typename TMapper, typename TContainerOrRef> - auto Map(TMapper&& mapper, TContainerOrRef&& container) { - return ::MakeMappedRange(std::forward<TContainerOrRef>(container), std::forward<TMapper>(mapper)); - } - - //! Usage: for (auto i : Map<int>(floats)) {...} - template <typename TMapResult, typename TContainerOrRef> - auto Map(TContainerOrRef&& container) { - return Map([](const auto& x) { return TMapResult(x); }, std::forward<TContainerOrRef>(container)); - } - - //! Usage: for (i32 x : Filter(predicate, container)) {...} - template <typename TPredicate, typename TContainerOrRef> - auto Filter(TPredicate&& predicate, TContainerOrRef&& container) { - return ::MakeFilteringRange(std::forward<TContainerOrRef>(container), std::forward<TPredicate>(predicate)); - } - -} +#pragma once + +#include "cartesian_product.h" +#include "concatenate.h" +#include "enumerate.h" +#include "filtering.h" +#include "mapped.h" +#include "zip.h" + +#include <util/generic/adaptor.h> +#include <util/generic/xrange.h> + +#include <tuple> +#include <algorithm> + + +namespace NFuncTools { + using ::Enumerate; + using ::Reversed; + using ::Zip; + using ::Concatenate; + using ::CartesianProduct; + + template <typename TValue> + auto Range(TValue from, TValue to, TValue step) { + return xrange(from, to, step); + } + + template <typename TValue> + auto Range(TValue from, TValue to) { + return xrange(from, to); + } + + template <typename TValue> + auto Range(TValue to) { + return xrange(to); + } + + //! Usage: for (i32 x : Map([](i32 x) { return x * x; }, a)) {...} + template <typename TMapper, typename TContainerOrRef> + auto Map(TMapper&& mapper, TContainerOrRef&& container) { + return ::MakeMappedRange(std::forward<TContainerOrRef>(container), std::forward<TMapper>(mapper)); + } + + //! Usage: for (auto i : Map<int>(floats)) {...} + template <typename TMapResult, typename TContainerOrRef> + auto Map(TContainerOrRef&& container) { + return Map([](const auto& x) { return TMapResult(x); }, std::forward<TContainerOrRef>(container)); + } + + //! Usage: for (i32 x : Filter(predicate, container)) {...} + template <typename TPredicate, typename TContainerOrRef> + auto Filter(TPredicate&& predicate, TContainerOrRef&& container) { + return ::MakeFilteringRange(std::forward<TContainerOrRef>(container), std::forward<TPredicate>(predicate)); + } + +} |