cpp-common/bt2c: add `bt2c::IsOneOf` trait
authorSimon Marchi <simon.marchi@efficios.com>
Tue, 23 Jan 2024 17:30:43 +0000 (17:30 +0000)
committerSimon Marchi <simon.marchi@efficios.com>
Mon, 29 Jan 2024 16:38:19 +0000 (11:38 -0500)
Add the `bt2c::IsOneOf` trait, which is used to check if a type is in a
list of types.

Change-Id: If95ebc542d0581afb3411fcaece6617bb4946612
Signed-off-by: Simon Marchi <simon.marchi@efficios.com>
Reviewed-on: https://review.lttng.org/c/babeltrace/+/11708
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
src/Makefile.am
src/cpp-common/bt2c/type-traits.hpp [new file with mode: 0644]

index dc046d9eab4b826e8e86947327f7a874c1f195be..148520ced5a937d9ebb52f959081b27fc2900974 100644 (file)
@@ -56,6 +56,7 @@ noinst_HEADERS = \
        cpp-common/bt2c/read-fixed-len-int.hpp \
        cpp-common/bt2c/safe-ops.hpp \
        cpp-common/bt2c/std-int.hpp \
+       cpp-common/bt2c/type-traits.hpp \
        cpp-common/bt2c/uuid.hpp \
        cpp-common/bt2c/vector.hpp \
        cpp-common/bt2s/make-unique.hpp \
diff --git a/src/cpp-common/bt2c/type-traits.hpp b/src/cpp-common/bt2c/type-traits.hpp
new file mode 100644 (file)
index 0000000..da8e0e0
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2023 Philippe Proulx <pproulx@efficios.com>
+ *
+ * SPDX-License-Identifier: MIT
+ */
+
+#ifndef BABELTRACE_CPP_COMMON_BT2C_TYPE_TRAITS_HPP
+#define BABELTRACE_CPP_COMMON_BT2C_TYPE_TRAITS_HPP
+
+#include <type_traits>
+
+namespace bt2c {
+
+/*
+ * Provides the member constant `value` equal to:
+ *
+ * `T` is in the list of types `Ts`:
+ *     `true`
+ *
+ * Otherwise:
+ *     `false`
+ */
+template <typename T, typename... Ts>
+struct IsOneOf : std::false_type
+{
+};
+
+template <typename T, typename... Ts>
+struct IsOneOf<T, T, Ts...> : std::true_type
+{
+};
+
+template <typename T, typename U, typename... Ts>
+struct IsOneOf<T, U, Ts...> : IsOneOf<T, Ts...>
+{
+};
+
+} /* namespace bt2c */
+
+#endif /* BABELTRACE_CPP_COMMON_BT2C_TYPE_TRAITS_HPP */
This page took 0.025672 seconds and 4 git commands to generate.