Talk:cpp/algorithm
Simple question: Why is count() listed here and distance() listed in the iterators library?--Gemini67 (talk) 06:35, 19 September 2014 (PDT)
- The most direct answer is probably that std::count is a part of the algorithms library in C++ (chapter 25 of the standard), while std::distance is part of the Iterators library (chapter 24 of the standard). They are also declared in different headers. Note that
std::count
does something with the elements of a sequence, whilestd::distance
operates on iterators only. --Cubbi (talk) 04:21, 19 September 2014 (PDT)- Thank you for the detailed explanation.
However, the question arose because I was looking for a count() without a condition == distance(). But I never used distance() before so I did not think about it ...
Is it possible to add a link to the iterators library, saying something like 'for more operations on iterators look here'?--Gemini67 (talk) 06:35, 19 September 2014 (PDT) - It's an interesting observation that count degenerates into distance: I made a note on std::count page. Many libraries in C++ are closely related, especially the ones that originated in STL (containers, algorithms, function objects, and iterators): I'm not sure it makes sense to single one out. --Cubbi (talk) 07:06, 19 September 2014 (PDT)
- Thank you for the detailed explanation.
134.130.191.106 05:51, 12 June 2015 (PDT)Would it be possible to show the return type of the algorithms in this page?
Rather a very general question with respect to the Wiki engine, but as the "problem" hit me the first time here, I ask here:
I now frequently link (from my C++ training documents) to en.cppreference.com pages, and sometimes I want to link directly to a sub-section. Usually this is quite easy by taking the title of the sub-section, replace spaces with underscore and append the result with a '#' to the page URL.
But I don't know how the parentheses - as in some subsection names of this page, e.g. "... (on sorted ranges)" - need to be mapped and what I tried naively doesn't appear to work.
Mwe (talk) 09:38, 12 July 2015 (PDT)
- It's http://en.cppreference.com/w/cpp/algorithm#Binary_search_operations_.28on_sorted_ranges.29. T. Canens (talk) 12:06, 12 July 2015 (PDT)
Is it appropriate to place for_each under non-modifying sequence operations?
If the elements in the sequence are mutable, it's possible to modify the elements with for_each algorithm.
Or do I misunderstand the terminology here?