How std::transform and std::plus work together?

<p>I was reading C++ reference and came across std::plus function with an example. Which is pretty straight forward, its simply adds lhs and rhs. The code was:</p><pre><br /><code>#include <functional><br />#include <iostream><br /><br />int main()<br />{<br /> std::string a = "Hello ";<br /> const char* b = "world";<br /> std::cout << std::plus<>{}(a, b) << '\n';<br />}<br /></code><br /></pre><p>output: Hello world</p><p>I changed it to</p><pre><br /><code>#include <functional><br />#include <iostream><br /><br />int main()<br />{<br /> int a = 5;<br /> int b = 1;<br /> std::cout << std::plus<int>{}(a, b) << '\n';<br />}<br /></code><br /></pre><p>output : 6</p><p>Now I made</p><pre><br /><code>foo vector = 10 20 30 40 50<br />bar vector = 11 21 31 41 51<br /></code><br /></pre><p>I called:</p><pre><br /><code>std::transform (foo.begin(), foo.end(), bar.begin(), foo.begin(), std::plus<int>());<br /></code><br /></pre><p>and it gave 21 41 61 81 101 which I understand it is adding up both foo and bar. But how it was passed to std::plus function?</p><br /><h2>Click here view more answers <a href="http://ift.tt/20RXA31">http://ift.tt/20RXA31</a></h2>

Nhận xét

Bài đăng phổ biến từ blog này

Align div to bottom of the page in bootstrap

Align elements inside an tag vertically

Javascript is unable to stop page loading