Hi!
Flibble is currently very cross due to the following code:
#include <cstdint>
#include <type_traits>
#include <variant>
#include <iostream>
template <typename T>
T foo(const std::variant<int64_t, double, std::string>& v)
{
T result;
std::visit([&result](auto&& a)
{
typedef std::decay_t<decltype(a)> vt;
if constexpr (std::is_same_v<vt, double>)
result = static_cast<T>(a);
else if constexpr (std::is_same_v<vt, int64_t>)
result = static_cast<T>(a);
else if constexpr (std::is_same_v<vt, std::string> && std::is_class_v<T>)
result = T::from_string(a); // Pfft
else
throw std::logic_error("wibble");
}, v);
return result;
}
int main()
{
std::cout << foo<double>(int64_t{});
}
Is the line marked "Pfft" legal or not? g++ (Wandbox HEAD) thinks it is whilst clang++ (Wandbox HEAD) thinks it is illegal. I would expect the constexpr if statement to not be considered if T isn't of class type.
https://wandbox.org/permlink/IcnMGxGSdAkBb2iP
/Flibble
--
"Snakes didn't evolve, instead talking snakes with legs changed into snakes." - Rick C. Hodgin
“You won’t burn in hell. But be nice anyway.” – Ricky Gervais
“I see Atheists are fighting and killing each other again, over who doesn’t believe in any God the most. Oh, no..wait.. that never happens.” – Ricky Gervais
"Suppose it's all true, and you walk up to the pearly gates, and are confronted by God," Byrne asked on his show The Meaning of Life. "What will Stephen Fry say to him, her, or it?"
"I'd say, bone cancer in children? What's that about?" Fry replied.
"How dare you? How dare you create a world to which there is such misery that is not our fault. It's not right, it's utterly, utterly evil."
"Why should I respect a capricious, mean-minded, stupid God who creates a world that is so full of injustice and pain. That's what I would say."