I always add a reserve when I know how many items I want to copy. But in this case it's easier to just use the std::vector constructor that constructs a vector with the contents of the range [first, last), i.e. keys = std::vector<GpgME::Key>(groupKeys.begin(), groupKeys.end());
And make groupKeys a const-reference to avoid a copy of the Keys set.