EDIT AFTER COMMENTS
Ok, after given answers and comments I ended up with something like this:
template< typename Container >
std::string to_query_params(Container&& container) // 1.
{
if (container.empty()){
return "";
}
std::string result;
for( const auto& item : container ) {
result.append("&")
.append(std::get<0>(item))
.append("=")
.append(std::get<1>(item)); // 2.
}
assert(result.size() > 0);
result[0]='?';
return result;
}
- we're independent of underlying container, be it
multimap,map,vector<tuple<string,string>>, etc; - and we're independent of
r/lvaluenessof param being able to callto_query_params(generate_params()); - as of the container - I'll opt for
std::vector<std::tuple<std::string, std::string>>, as we do not need to access elements, but iterate over them, so linear memory block will be cache-friendly;
-
- thank's to
appendwe're not creating useless copies;
- thank's to
std::stringstreamis hudge and heavy, and I tend to avoid it as much as I can;