I just watched Stephan T. Lavavej talk at CppCon 2018
on "Class Template Argument Deduction", where at some point he incidentally says:
In C++ type information almost never flows backwards ... I had to say "almost" because there's one or two cases, possibly more but very few.
Despite trying to figure out which cases he might be referring to, I couldn't come up with anything. Hence the question:
In which cases the C++17 standard mandates that type information propagate backwards?
Here is at least one case:
if you do
foo f; int x = f; double y = f;
, type information will flow "backwards" to figure out whatT
is inoperator T
.You can use this in a more advanced way:
so now I can do
and it works.
Of course, why not just do
{1,2,3}
? Well,{1,2,3}
isn't an expression.which, admittedly, require a bit more wizardry: Live example. (I have to make the deduce return do a SFINAE check of F, then make the F be SFINAE friendly, and I have to block std::initializer_list in deduce_return_t operator T.)