Quantcast
Channel: What are the type conversion rules for parameters and return values of lambdas? - Stack Overflow
Viewing all articles
Browse latest Browse all 5

Answer by Jonathan Wakely for What are the type conversion rules for parameters and return values of lambdas?

$
0
0

the conversion from a reference to a value looks strange to me

Why?

Does this look strange too?

int foo(int i) { return i; }void bar(const int& ir) { foo(ir); }

This is exactly the same. A function taking an int by value gets called by another function, taking an int by const-reference.

Inside bar the variable ir gets copied, and the return value gets ignored. That's exactly what happens inside the std::function<void(const int&)> when it has a target with the signature int(int).


Viewing all articles
Browse latest Browse all 5

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>