-
Hi I was saving keys in a vector like this: std::vector<std::string> tracks;
const nlohmann::json config(nlohmann::json::parse(f));
for (const auto& track : config.items())
{
tracks.emplace_back(track.key());
} That was fine but then cppcheck was suggesting to use std::vector<std::string> tracks;
const nlohmann::json config(nlohmann::json::parse(f));
std::transform(
config.items().begin(),
config.items().end(),
tracks.begin(),
[](const auto& track){return track.key();}); Is doing something like this possible? I found an issue about using std algorithms here: #1045 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Are you missing code in the sample? You need to either set the size of |
Beta Was this translation helpful? Give feedback.
Are you missing code in the sample? You need to either set the size of
tracks
to be the same as the number of entries inconfig
or use theback_inserter
wrapper to resize the vector as it goes.https://godbolt.org/z/xnTMPdTKr