前言
Under the new standard we can list initialize the return value.
代码测试
cpp
#include<iostream>
#include<string>
#include<vector>
std::pair<std::string, int>
process(std::vector<std::string>& v)
{
if (!v.empty())
{
return { v.back(), v.back().size() }; // list initialize返回
}
else
{
return std::pair<std::string, int>();
}
}
int main()
{
std::vector<std::string> vecT{ "hablee","yuki" };
std::pair<std::string, int> re = process(vecT);
std::cout << re.first << ", " << re.second << std::endl;
return 0;
}