Namespaces
Variants
Views
Actions

Talk:cpp/algorithm

From cppreference.com
< Talk:cpp
Revision as of 06:06, 19 September 2014 by Cubbi (Talk | contribs)

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, while std::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)