Talk:cpp/utility/variant/visit

keyword "overloaded"?
In the sample at the bottom of the page I found this... what is "overloaded"? this does not compile with VS 2017

for (auto& v: vec) { std::visit(overloaded {

--Chris guzak (talk) April 2017


 * overloaded is a struct that inherits from its arguements (the lambdas) and exposes their function call operator (for calls by visit). Guessing it doesn't work yet in MSVS due to the use of class template deduction --Ybab321 (talk) 23:09, 10 April 2017 (PDT)

mention corresponding proposal
Would it be helpful if we mention some related proposal? For example, following two are worth mentioning:


 * 1) P0051R3 generic overload function
 * 2) P1371R2 pattern matching

Especially P1371 which got revised last month. --Franklin Yu (talk) 14:59, 19 February 2020 (PST)
 * We don't cover proposals that have not made their way into the working draft. They can see significant changes or be abandoned or rejected altogether. Defect reports are an exception - if the current specification is clearly defective, we may cover them even if the resolution isn't settled. Given what has transpired during the C++20 cycle, I'm dubious of the value of covering features that have made their way into the working draft. It looks like the committee is increasingly in the habit of voting a questionably-baked feature in and then patching it up over multiple meetings (or in the case of some of the features, until the very last moment), resulting in significant waste of effort on our part. T. Canens (talk) 05:35, 20 February 2020 (PST)

std::visit calls ADL get rather than std::get
According to the: http://eel.is/c++draft/variant.visit#1 std::visit calls get, rather than std::get, which should enable ADL.

Thus changing that example to the version without std:: — Preceding unsigned comment added by DaPi (talk • contribs)
 * Unless the standard explicitly says ADL, there's no ADL. http://eel.is/c++draft/contents#3, http://eel.is/c++draft/global.functions#4. T. Canens (talk) 07:15, 24 February 2020 (PST)


 * You are right, sorry then. Was that the intention in this case, though? Please note, that forward is explicitly said to be from the namespace std::. — Preceding unsigned comment added by DaPi (talk • contribs)
 * Yes. and  are  qualified as a matter of style. T. Canens (talk) 08:20, 24 February 2020 (PST)

Multiple variants
Maybe we can add an example usage of how to supply multiple variants to visit. E.g.

std::visit([](auto a, auto b) {    // ...   }, v, w);