Why isn't std::variant allowed to equal compare with one of its alternative types?

why isn't my brain working supplements
why isn't my brain working pdf
why isn't my brain working audiobook
why isn't my brain working review
why isn't my brain working pdf download
why isn't my brain working reddit
kharrazian brain book
is netflix down or is it just me

For example, it should be very helpful to equal compare a std::variant<T1, T2> with a T1 or T2. So far we can only compare with the same variant type.

Why Isn't The UP Part Of Wisconsin?, Wisconsin shares more than 200 miles of border with the Upper Peninsula. Michigan and the UP share a bridge. Why didn't the state's northern� Black D.C. residents fought to change their city’s unequal status during the civil rights movement, and won some key victories.The first was the right to vote for the president and vice

A variant may have multiple duplicates of the same type. E.g. std::variant<int, int>.

A given instance of std::variant compares equal to another if and only if they hold the same variant alternative and said alternatives' values compare equal.

Thus, a std::variant<int, int> with index() 0 compares not equal to a std::variant<int, int> with index() 1, despite the active variant alternatives being of the same type and same value.

Because of this, a generic "compare to T" was not implemented by the standard. However, you are free to design your own overload of the comparison operators using the other helper utilities in the <variant> header (e.g. std::holds_alternative and std::get<T>).

Why isn't ventilation part of the conversation on reopening schools , Covid-19 is mainly transmitted through respiratory droplets in the air. Why isn't improving ventilation a key part of the effort to reopen schools? Why Isn’t The Media Interviewing Portland’s Rioters? July 23, 2020 By David Marcus. Among the many confusions beset upon our boondoggled society at the moment is the question of just who the

I can't answer the why part of the question but since you think it would be useful to be able to compare a std::variant<T1, T2> with a T1 or T2, perhaps this can help:

template<typename T, class... Types>
inline bool operator==(const T& t, const std::variant<Types...>& v) {
    const T* c = std::get_if<T>(&v);
    if(c)
        return *c == t;
    else
        return false;
}

template<typename T, class... Types>
inline bool operator==(const std::variant<Types...>& v, const T& t) {
    return t == v;
}

Why Isn't Netflix Working, Why isn't Netflix working? If Netflix isn't working, you may be experiencing a network connectivity issue, an issue with your device, or an issue� But that isn’t true for every interesting set of numbers. As an example, let’s look at the set of numbers of the form a + b √-5, or a +i b √5, where a and b are both integers and i is the

Why isn't the Netherlands underwater? - Stefan Al, Dig into the incredible engineering of the Netherlands' Delta Works— the most sophisticated Duration: 5:24 Posted: Mar 24, 2020 Why isn't Netflix working? If Netflix isn't working, you may be experiencing a network connectivity issue, an issue with your device, or an issue with your Netflix

Why isn't my app working?, Why isn't my app working? If you're having issues with your device or app, try these troubleshooting tricks: Try force-closing the app and reopening. Make sure � Why Isn't My Printer Printing? 6 printing issues you can fix. by. Tom Nelson. Writer. Tom Nelson is an engineer, programmer, network manager, and computer network and

Why Isn't Sustainable Fashion More Affordable?, In spite of the growing demand for eco-friendly clothing, most consumers don't want to pay more for it. So, what's the solution? We speak to� The Most Common Reason Your Disk Is Missing. You grabbed a nice big hard disk on sale, you cracked open your computer case, plugged the drive into the motherboard and power supply with the appropriate cables (no? better double check that before you keep reading), and when you booted your computer back up the new hard drive was nowhere to be found.

Comments
  • I think c++20 just added it to the draft with the mothership proposal
  • @GuillaumeRacicot In that same link, I believe it's saying the int would be implicitly cast to std::variant<int, std::string> to satisfy the comparison function signature. For an int, that's probably trivial. But for a string, that could mean a copy.
  • Shouldn't the compare also work in C++17? the operator== is a freestanding function. And variant has a non-explicit conversion-constructor, so variant<T1, T2>() == T1() should convert T1 to variant<T1, T2> and it shuould find the freestanding operator==. Actually after a check I found out that it does not work. Why is that so?
  • Actually following code works: struct X { template<class T> X(T&&) {} }; bool operator==(X const&, X const&); X x(10); bool b = x==10; So it seemes to be related to operator== being a template.
  • This is not an answer to the question, it's just a statement of the situation. You did not say why "a given instance of std::variant compares equal to another if and only if etc. etc."
  • When comparing an int with std::variant<int, int> it could compare the active member with that int.
  • @einpoklum The standard just decided it should be that way. I'm explaining the reason (in terms of how the comparison operators work in the standard) for why a generic comparison to T is not in the standard.
  • @MaximEgorushkin You may want it to be like that, but that's not what the standard decided.
  • @CruzJean Well, in variant visitor you cannot distinguish between the two now - the comparison can be just as oblivious. I am not sure what use case the standard had in mind, however, one can wrap an integer into a unique class and get more mileage out of that.