mapbox / variant

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

cant use bool and string in a variant #179

Closed mahdy-asady closed 4 years ago

mahdy-asady commented 4 years ago

i cant use below code: variant<int, double, string, bool> a = "Test";

but when i remove bool variable type it works fine!

lightmare commented 4 years ago
variant<int, double, string, bool> a = "Test";

is ambiguous, because the compiler has two equally good conversions available: a) const char* to bool (implicit pointer-to-bool conversion) b) const char* to std::string (using std::string conversion constructor)

You need to disambiguate it yourself, e.g.:

variant<int, double, string, bool> a = string("Test");