Talk:cpp/algorithm/inner product


[edit] Example

I am a big fan of std::inner_product because of my prior exposure to APL (thank you, C++ Committee, for mentioning APL in the footnote for std::accumulate!). In that language, generalized inner product is a language primitive and has a million clever uses (see chapters 18 through 21 of APL Idiom library for example). Could we incorporate one of those, say idiom #328 "count pairwise matches", inner_product(v1.begin(), v1.end(), v2.begin(), 0, std::plus<int>(), std::equal_to<T>());, to show that it's not just for linear algebra? Or would it be too much for a C++ reference? In my opinion, examples that simply repeat in code what the page just said in English feel almost redundant. --Cubbi 13:17, 18 August 2011 (PDT)

Of course. It would be great since that is what the examples are for - to show the non-obvious things that can be done with the API. The size of the whole example code doesn't matter as it is placed at the end of the page. So you can add as much interesting cases as you feel is needed. Speaking about 'too much for a C++ reference', all those restrictions are here just to prevent the mess that takes place once everyone starts explaining obvious things and, what is even worse, does that in detail. So if you think something is sufficiently complex or interesting, feel free to add to the article. E.g. see notes at std::make_heap P12 13:43, 18 August 2011 (PDT)
Actually, I can probably mod the existing example since it already calls inner_product twice. --Cubbi 13:31, 18 August 2011 (PDT)