aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yt/misc/concepts.h
diff options
context:
space:
mode:
authorAlexander Smirnov <alex@ydb.tech>2024-04-23 09:07:41 +0000
committerAlexander Smirnov <alex@ydb.tech>2024-04-23 09:07:41 +0000
commitb35b2344f47ddaef21fb74c7f5cad9cd91d3cb45 (patch)
treee7b382f5c6cce63ce1e160d51ad1aac846ba2905 /library/cpp/yt/misc/concepts.h
parentb3bee3aa6d7c8767695b8917484e6bb488e9c8ca (diff)
parentae5472d0928c374dc719b154c9dcb2be6e0a0695 (diff)
downloadydb-b35b2344f47ddaef21fb74c7f5cad9cd91d3cb45.tar.gz
Merge branch 'rightlib' into mergelibs-240423-0906
Diffstat (limited to 'library/cpp/yt/misc/concepts.h')
-rw-r--r--library/cpp/yt/misc/concepts.h49
1 files changed, 49 insertions, 0 deletions
diff --git a/library/cpp/yt/misc/concepts.h b/library/cpp/yt/misc/concepts.h
new file mode 100644
index 00000000000..976c707ffec
--- /dev/null
+++ b/library/cpp/yt/misc/concepts.h
@@ -0,0 +1,49 @@
+#pragma once
+
+#include <concepts>
+
+namespace NYT {
+
+////////////////////////////////////////////////////////////////////////////////
+
+namespace NDetail {
+
+template <class T, class TSignature>
+struct TIsInvocable;
+
+template <class T, class TResult, bool NoExcept, class... TArgs>
+struct TIsInvocable<T, TResult(TArgs...) noexcept(NoExcept)>
+{
+private:
+ static constexpr bool IsInvocable_ = requires (T&& t, TArgs&&... args) {
+ { std::forward<T>(t)(std::forward<TArgs>(args)...) } -> std::same_as<TResult>;
+ };
+
+ static constexpr bool IsNoThrowInvocable_ = requires (T&& t, TArgs&&... args) {
+ { std::forward<T>(t)(std::forward<TArgs>(args)...) } noexcept -> std::same_as<TResult>;
+ };
+
+public:
+ static constexpr bool Value =
+ IsInvocable_ &&
+ (!NoExcept || IsNoThrowInvocable_);
+};
+
+} // namespace NDetail
+
+////////////////////////////////////////////////////////////////////////////////
+
+template <class TObject, class TScalar>
+concept CScalable = requires (TObject object, TScalar scalar)
+{
+ { object * scalar } -> std::same_as<TObject>;
+};
+
+////////////////////////////////////////////////////////////////////////////////
+
+template <class T, class TSignature>
+concept CInvocable = NDetail::TIsInvocable<T, TSignature>::Value;
+
+////////////////////////////////////////////////////////////////////////////////
+
+} // namespace NYT