My reference is to the example provided under the following:
I am trying to constrast the following usage of std::next in the example,
std::string s =
std::accumulate(
std::next(v.begin()),
v.end(),
std::to_string(v[0]), // start with first element
dash_fold
);
with the usage example provided for std::next
Given that in the referred to example for std::accumulate usage, the following is the signature of dash_fold:
auto dash_fold = [](std::string a, int b){...}
I am assuming that the construct std::next(v.begin()), v.end(), std::to_string(v[0]...
above should produce
int, string
which is reversing the order of parameters that dash_fold expects; is this understanding correct? Or am I missing something?
TIA
>Solution :
The referenced manual is very detailed.
constexpr T accumulate( InputIt first, InputIt last, T init,
BinaryOperation op );
T in your case is the type of std::to_string(v[0]), is std::string.
op:
Ret fun(const Type1 &a, const Type2 &b);The type
Type1must be such that an object of typeTcan be implicitly converted toType1.
Type1 must be such that an object of type std::string can be implicitly converted to Type1. If the first parameter type is int, then std::string cannot be implicitly converted to int – fail. If the first parameter type is std::string, then it works well.