Namespaces
Variants
Views
Actions

Talk:cpp/algorithm

From cppreference.com
< Talk:cpp
Revision as of 05:08, 2 July 2020 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)

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)

Contents

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 std::for_each algorithm.

Or do I misunderstand the terminology here?

'Modifying' in this context is referring to the sequence itself rather than the values within the sequence. std::for_each won't invalidate any iterators (unlike e.g. std::reverse), nor is it capable of producing a new sequence (e.g. std::transform). --Ybab321 (talk) 06:15, 29 November 2017 (PST)

Explicit statement for empty ranges should be added

I think there should be added an explicit statement that executing any algo on empty range (first==last) is safe and either a noop or returns last immediately (if algo returns something or not).

192.64.159.11 09:46, 16 March 2018 (PDT) Slava

Making the constrained algorithms more obvious

I suspect that newcomers will skip past the constrained algorithms section straight to the Cpp17Algorithms (sic) below, so it might be worthwhile moving the unconstrained algorithms into a Legacy Algorithms sub-page. Cjdb (talk) 20:11, 1 July 2020 (PDT)

how about inlining the technical differences in the same cpp/algorithm page, keeping the grouping by type, e.g.
Modifying sequence operations
copies a range of elements to a new location
(function template) [edit]
copies a range of elements to a new location
(niebloid)[edit]
(C++11)
copies a number of elements to a new location
(function template) [edit]
copies a number of elements to a new location
(niebloid)[edit]
we'd have to drop "included in header" to avoid noise in that list --Cubbi (talk) 06:08, 2 July 2020 (PDT)