I wrote a code as follows:
#include <iostream>
#include <vector>
using type = std::vector<std::string>;
int main()
{
int query = 5;
std::vector< type > answer;
answer.reserve(query);
auto vecReturn = [](const std::string& x, const std::string& y) -> decltype(auto)
{
std::vector<std::string> tempVec = {x, y};
return std::move(tempVec);
};
while(query--)
{
std::string xName, yName;
std::cin >> xName >> yName;
answer.emplace_back( vecReturn(xName, yName) );
}
return 0;
}
I can rewrite the above without the lambda function, something like follows:
using type = std::vector<std::string>;
int query = 5;
std::vector< type > answer; // group set
answer.reserve(query);
while(query--)
{
std::string xName, yName;
std::cin >> xName >> yName;
type tempVec = { xName, yName };
answer.emplace_back( tempVec );
}
Which looks pretty less code than the first one. Now the question is,
- Is there any efficiency differences between in these two ways, considering that,
query
could be up to the maximum integer numeric limit. - If so, which one of above mentioned ways, would you suggest me to do?
Thanks for your time.
Aucun commentaire:
Enregistrer un commentaire