aboutsummaryrefslogtreecommitdiffhomepage
path: root/development/c++/meta3.cc
diff options
context:
space:
mode:
authorjohannst <johannst@users.noreply.github.com>2022-08-24 16:10:10 +0000
committerjohannst <johannst@users.noreply.github.com>2022-08-24 16:10:10 +0000
commit865999619eb8e79a3e36ac17f782c7c302ca923e (patch)
tree797a40e2ebd99febb6369d4f235ffa16041a6a2c /development/c++/meta3.cc
parent25b609d0c70d49dd62479ce03578704e62712bd8 (diff)
downloadnotes-865999619eb8e79a3e36ac17f782c7c302ca923e.tar.gz
notes-865999619eb8e79a3e36ac17f782c7c302ca923e.zip
deploy: e6f439cb43ee51b13ed4d29ec84ac5450556b163
Diffstat (limited to 'development/c++/meta3.cc')
-rw-r--r--development/c++/meta3.cc22
1 files changed, 22 insertions, 0 deletions
diff --git a/development/c++/meta3.cc b/development/c++/meta3.cc
new file mode 100644
index 0000000..5dce54a
--- /dev/null
+++ b/development/c++/meta3.cc
@@ -0,0 +1,22 @@
+// Copyright (C) 2022 johannst
+
+#include <type_traits>
+
+template<typename T, typename... U>
+struct any_of : std::false_type {};
+
+// Found our type T in the list of types U.
+template<typename T, typename... U>
+struct any_of<T, T, U...> : std::true_type {};
+
+// Pop off the first element in the list of types U,
+// since it didn't match our type T.
+template<typename T, typename U0, typename... U>
+struct any_of<T, U0, U...> : any_of<T, U...> {};
+
+// Convenience template variable to invoke meta function.
+template<typename T, typename... U>
+constexpr bool any_of_v = any_of<T, U...>::value;
+
+static_assert(any_of_v<int, char, bool, int>, "");
+static_assert(!any_of_v<int, char, bool, float>, "");