mapbox / variant

C++11/C++14 Variant
BSD 3-Clause "New" or "Revised" License
371 stars 100 forks source link

std::is_copy_constructible::value is always true for variant<Ts...> #151

Open jplatte opened 7 years ago

jplatte commented 7 years ago

The copy constructor only actually compiles when all member types are copyable, as it should. However, when checking whether the variant type is copy-constructible via SFINAE, e.g. with std::is_copy_constructible, you will always get true, because the copy constructor always exists, whether or not it is valid. The same applies to move constructors, and copy / move assignment operators.

I first thought I could fix this with a simple enable_if on each of the methods, but as it turns out I can't because if you make templates out of any of these special methods, they are not those special methods anymore. I did find a solution on StackOverflow, though I'm not entirely certain if it might introduce unwanted side effects. Could you have a look? In case it seems unproblematic to you, I would be happy to try implementing it here.