From e6f439cb43ee51b13ed4d29ec84ac5450556b163 Mon Sep 17 00:00:00 2001 From: Johannes Stoelp Date: Wed, 24 Aug 2022 18:09:52 +0200 Subject: c++: add any_of meta fn example --- src/development/c++/meta3.cc | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/development/c++/meta3.cc (limited to 'src/development/c++/meta3.cc') diff --git a/src/development/c++/meta3.cc b/src/development/c++/meta3.cc new file mode 100644 index 0000000..5dce54a --- /dev/null +++ b/src/development/c++/meta3.cc @@ -0,0 +1,22 @@ +// Copyright (C) 2022 johannst + +#include + +template +struct any_of : std::false_type {}; + +// Found our type T in the list of types U. +template +struct any_of : std::true_type {}; + +// Pop off the first element in the list of types U, +// since it didn't match our type T. +template +struct any_of : any_of {}; + +// Convenience template variable to invoke meta function. +template +constexpr bool any_of_v = any_of::value; + +static_assert(any_of_v, ""); +static_assert(!any_of_v, ""); -- cgit v1.2.3