Closed ukreator closed 7 years ago
This is caused by X
being constructible from variant<Types...>
and
template<typename T, ...> variant(T&&)
being a better match than
variant(variant<Types...> const& old)
when the actual argument is a non-const reference.
Possible solutions:
variant(variant<Types...> & old)
&& !is_same<variant<Types...>, typename Traits::value_type>::value
to enable_if
in the universal constructor templateThanks for reporting @ukreator and for the thoughts on solutions @lightmare. @artemp is out on vacation this week but I know he's planning a v1.1.x release soon after returning. I've assigned this to 1.1.3 to consider fixing before the next release.
@lightmare - thanks for digging! Adding an extra check in universal ctor and explicitly disabling passing variants in there is the winner:
&& !std::is_same<variant<Types...>, typename Traits::value_type>::value
@ukreator - Thanks for reporting and providing test-case !
Simple code snippet to reproduce the issue:
boost::variant works fine in this case. This issue was originally spotted by random failures after replacing boost::variant with map box::variant. One of the types in the list was boost::any which has a templated constructor like in struct X above.