optional
optional copied to clipboard
CTAD on MSVC fails
Hi, first of all thanks for this library!
On MSVC 19.21 with C++17, CTAD fails with tl::optional whereas it works with std::optional:
tl::optional o = 3; // Cannot deduce T
std::optional o = 3; // Deduces T to be int
I think this is just a case of missing std::optional's deduction guide, since adding that in fixes it, but strangely Clang and GCC don't seem to need the guide and deduce T to be int anyway. I don't know enough about CTAD to know exactly what's going on here, so sorry if this isn't actually a bug in tl::optional and is instead a compiler bug.
Thanks for the report! Ah, it's because MSVC doesn't set __cplusplus properly unless you pass /Zc:__cplusplus, and the deduction guide is behind an ifdef. Will see if there's a more foolproof way of detecting C++17 mode for MSVC without that switch.
Ah gotcha, that's good to know in general! I'll set that switch for now, thanks :+1: