In the following example, the last line fails because the conversion operator of JSON has to choose between two possibilities:
std::vector<int>::operator=(std::vector<int>&&)std::vector<int>::operator=(std::initializer_list<int>)
How can I constrain JSON::operator T() so it ignores the initializer_list overload?
struct JSON
{
using StorageType = std::variant<
int,
float,
std::string,
std::vector<int>,
std::vector<float>
>;
StorageType storage;
template<class T>
operator T() const {
return std::get<T>(storage);
}
};
int main(int argc, char* argv[])
{
const JSON json;
std::vector<int> numbers;
numbers = json; // more than one operator '=' matches these operands
return 0;
}