aboutsummaryrefslogtreecommitdiffstats
path: root/library
diff options
context:
space:
mode:
authorbabenko <babenko@yandex-team.com>2022-10-27 20:26:32 +0300
committerbabenko <babenko@yandex-team.com>2022-10-27 20:26:32 +0300
commit83b8a0dc3ee65a7ea496298f9d8a427f920151d1 (patch)
treebe3c224ac1e22ba1afb5e6a336de4c11d88ff5d8 /library
parent787835bd59a8743ef2cab69d02818038b1baa771 (diff)
downloadydb-83b8a0dc3ee65a7ea496298f9d8a427f920151d1.tar.gz
Introduce PP_DEPAREN
Diffstat (limited to 'library')
-rw-r--r--library/cpp/yt/misc/preprocessor.h9
-rw-r--r--library/cpp/yt/misc/unittests/preprocessor_ut.cpp8
2 files changed, 17 insertions, 0 deletions
diff --git a/library/cpp/yt/misc/preprocessor.h b/library/cpp/yt/misc/preprocessor.h
index 9afd3ae902..719973c0f1 100644
--- a/library/cpp/yt/misc/preprocessor.h
+++ b/library/cpp/yt/misc/preprocessor.h
@@ -52,6 +52,15 @@
#define PP_EMPTY()
//! \endcond
+//! Removes the enclosing parens, if any.
+#define PP_DEPAREN(...) PP_DEPAREN_A(PP_DEPAREN_C __VA_ARGS__)
+//! \cond Implementation
+#define PP_DEPAREN_C(...) PP_DEPAREN_C __VA_ARGS__
+#define PP_DEPAREN_A(...) PP_DEPAREN_B(__VA_ARGS__)
+#define PP_DEPAREN_B(...) PP_DEPAREN_D_ ## __VA_ARGS__
+#define PP_DEPAREN_D_PP_DEPAREN_C
+//! \endcond
+
//! Performs (non-lazy) conditional expansion.
/*!
* \param cond Condition; should expands to either \c PP_TRUE or \c PP_FALSE.
diff --git a/library/cpp/yt/misc/unittests/preprocessor_ut.cpp b/library/cpp/yt/misc/unittests/preprocessor_ut.cpp
index 397e2a6a61..b712d8a48f 100644
--- a/library/cpp/yt/misc/unittests/preprocessor_ut.cpp
+++ b/library/cpp/yt/misc/unittests/preprocessor_ut.cpp
@@ -96,6 +96,14 @@ TEST(TPreprocessorTest, IsSequence)
EXPECT_STREQ("PP_FALSE", PP_STRINGIZE(PP_IS_SEQUENCE(PP_NIL)));
}
+TEST(TPreprocessorTest, Deparen)
+{
+ EXPECT_STREQ("a", PP_STRINGIZE(PP_DEPAREN(a)));
+ EXPECT_STREQ("a", PP_STRINGIZE(PP_DEPAREN((a))));
+ EXPECT_STREQ("( a, b)", PP_STRINGIZE((PP_DEPAREN(a, b))));
+ EXPECT_STREQ("( a, b)", PP_STRINGIZE((PP_DEPAREN((a, b)))));
+}
+
////////////////////////////////////////////////////////////////////////////////
} // namespace