I am new to C++. I was trying using the accumulate algorithm from the numeric library. Consider the following code segment. It turns out that the c ...
I am new to C++. I was trying using the accumulate algorithm from the numeric library. Consider the following code segment. It turns out that the c ...
Let's say : This algorithm takes a range of iterators for the container and a predicate. It takes an LegacyRandomAccessIterator. I do understand th ...
I have a std::vector<vec3> points where vec3 has float x, y, z. I want to find the min/max bounds of all the points. I.e. the min and max of al ...
Given a std::vector of vertices containing some 3d integer data: I want to calculate distances between pair of adjacent vertex: I have the follo ...
I have a vector of integers: Given that values.size() will always be even. I simply want to convert the adjacent elements into a pair, like this: ...
Using the following containers: I need to construct a sorted output container std::set<std::tuple<std::string, int, int>> using the s ...
Given a string: Is it possible to transform it to lowercase and remove all non-alpha characters in a single pass? Expected result: I know you c ...
I came up with this question after reading the excellent answer of std::next_permutation Implementation Explanation. Please refer to that post for an ...
Maybe I'm missing something. Is there a function in <algorithm> that does this? If not, what would you call it? It seems like a particular flavo ...
I was just curious how some of the C++ algorithms check the range of the result/output container when you only provide the range of the input? For exa ...
The following snipped does not compile with GCC 10 (Compiler Explorer link): because T is not Cpp17CopyAssignable: I cannot find such requiremen ...
In C++14, I have a std::vector of values for which I want to remove all elements that match a given value and I do not care about preserving the order ...
Short Version Currently, I manually create a lambda function for the new [], as follows: This lambda is later used as a generator function in the ...
C++20 added starts_with, ends_with to std::string. Is there a nice way to get it to be case insensitive? Note that perf matters so I do not want to ...
Why swap() in STL algorithm don't take address of a variable and passing variable work just fine but in C++ call by value don't change actual value bu ...
Given this piece of code: Is there a standard way to parallelize the body of void f(std::vector<T> &u, std::vector<int> const & ...
I have N numbers and I want to sort each number by digit. ( In my original problem I want to make the largest number by these (greedy approach)) For e ...
If I have a std::string: and a loop that modifies it in-place, like this: I can replace it with the equivalent transform: and these snippets ...
I'd like to know if it is possible to use std::back_inserter to create a vector of only a single element from a more complex struct. For example, in t ...
I have a nested loop and I am hoping to rewrite it using STL algorithms. Can someone help me out? ...