summaryrefslogtreecommitdiffstats
path: root/library/cpp
diff options
context:
space:
mode:
Diffstat (limited to 'library/cpp')
-rw-r--r--library/cpp/yt/misc/preprocessor.h8
-rw-r--r--library/cpp/yt/misc/unittests/preprocessor_ut.cpp13
2 files changed, 21 insertions, 0 deletions
diff --git a/library/cpp/yt/misc/preprocessor.h b/library/cpp/yt/misc/preprocessor.h
index 5b929a03b59..818c3be3546 100644
--- a/library/cpp/yt/misc/preprocessor.h
+++ b/library/cpp/yt/misc/preprocessor.h
@@ -50,6 +50,7 @@
#define PP_RIGHT_PARENTHESIS )
#define PP_COMMA() ,
#define PP_EMPTY()
+#define PP_EMPTINESS
//! \endcond
//! Removes the enclosing parens, if any.
@@ -123,6 +124,13 @@
#define PP_ONE_OR_NONE(a, ...) PP_THIRD(a, ## __VA_ARGS__, a)
#define PP_THIRD(a, b, ...) __VA_ARGS__
+//! Checks whether emptiness was passed.
+#define PP_IS_EMPTY(...) PP_IS_EMPTY_A(__VA_ARGS__)
+//! \cond Implementation
+#define PP_IS_EMPTY_A(...) PP_FIRST(__VA_OPT__(PP_FALSE,) PP_TRUE)
+#define PP_FIRST(a, ...) a
+//! \endcond
+
//! \cond Implementation
#define PREPROCESSOR_GEN_H_
#include "preprocessor-gen.h"
diff --git a/library/cpp/yt/misc/unittests/preprocessor_ut.cpp b/library/cpp/yt/misc/unittests/preprocessor_ut.cpp
index b712d8a48f5..e4c88a7fe8e 100644
--- a/library/cpp/yt/misc/unittests/preprocessor_ut.cpp
+++ b/library/cpp/yt/misc/unittests/preprocessor_ut.cpp
@@ -104,6 +104,19 @@ TEST(TPreprocessorTest, Deparen)
EXPECT_STREQ("( a, b)", PP_STRINGIZE((PP_DEPAREN((a, b)))));
}
+TEST(TPreprocessorTest, IsEmpty)
+{
+ EXPECT_EQ(1, PP_IF(PP_IS_EMPTY(), 1, 2));
+ EXPECT_EQ(1, PP_IF(PP_IS_EMPTY(PP_EMPTINESS), 1, 2));
+ EXPECT_EQ(1, PP_IF(PP_IS_EMPTY(PP_EMPTY()), 1, 2));
+ EXPECT_EQ(1, PP_IF(PP_IS_EMPTY(PP_EMPTY PP_LEFT_PARENTHESIS PP_RIGHT_PARENTHESIS), 1, 2));
+
+ EXPECT_EQ(2, PP_IF(PP_IS_EMPTY(()), 1, 2));
+ EXPECT_EQ(2, PP_IF(PP_IS_EMPTY(PP_EMPTY), 1, 2));
+ EXPECT_EQ(2, PP_IF(PP_IS_EMPTY(0), 1, 2));
+ EXPECT_EQ(2, PP_IF(PP_IS_EMPTY(hello), 1, 2));
+}
+
////////////////////////////////////////////////////////////////////////////////
} // namespace