Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Shush cppcheck, you don't know your type traits (but we run an outdat…
…ed you, so I forgive you) https://godbolt.org/z/Wo7dPqvs3 ```c++ #include <fmt/compile.h> #include <fmt/format.h> #include <type_traits> #include <variant> using VariantType = std::variant<int, unsigned int>; template <class> inline constexpr bool always_false_v = false; constexpr void test_type(auto&& arg) { using T = std::decay_t<decltype(arg)>; if constexpr (std::is_same_v<T, unsigned int>) { fmt::print(FMT_COMPILE("Hey there unsigned! cppcheck thought you wouldn't be here\n")); } else if constexpr (std::is_same_v<T, int>) { fmt::print(FMT_COMPILE("Hello integer, how are you?\n")); } else { static_assert(always_false_v<T>, "non-exhaustive visitor!"); } } constexpr void test_variant_type(const VariantType& arg) { std::visit( [](auto&& arg) { using T = std::decay_t<decltype(arg)>; if constexpr (std::is_same_v<T, int>) { fmt::print(FMT_COMPILE("Hello integer, how are you?\n")); } else if constexpr (std::is_same_v<T, unsigned int>) { fmt::print(FMT_COMPILE("Hey there unsigned! cppcheck thought you wouldn't be here\n")); } else { static_assert(always_false_v<T>, "non-exhaustive visitor!"); } }, arg); } int main() { int i = 10; test_type(i); unsigned u = 10; test_type(u); fmt::print("Variant\n"); auto iv = VariantType(i); auto uv = VariantType(u); test_variant_type(iv); test_variant_type(uv); } ```
- Loading branch information