Here I assume listPair
is already filled, because there's no way to get that string otherwise.
You could loop through the collections directly.
auto a_cur = listA.begin(), a_end = listA.end();
auto pair_cur = listPair.begin();
for (; a_cur != a_end; ++ a_cur, ++ pair_cur) {
pair_cur->first = *a_cur;
}
or use the "binary" version of std::transform
, but this will involve copying the string:
std::transform(listA.begin(), listA.end(), listPair.begin(), listPair.begin(),
[](double a, std::pair<double, string> b) {
return std::make_pair(a, b.second);
});