有人知道boost::split
的快捷方式吗?那个
std::vector<std::string> args;
boost::split(args, argsString, boost::is_any_of("\t "), boost::token_compress_on);
成为
auto const args = boost::split(args, argsString, boost::is_any_of("\t "), boost::token_compress_on);
or
auto const args = boost::split<std::vector>(args, argsString, boost::is_any_of("\t "), boost::token_compress_on);
基本相同,例如,trim
- trim_copy
。
最佳答案
据我所知,Boost 中不存在任何捷径。
就个人而言,我为 split
写了一个简单的包装器,因为我遇到了和你一样的问题:
template <typename RangeT, typename PredicateT>
std::vector<std::string> split(RangeT& Input, PredicateT Pred,
boost::algorithm::token_compress_mode_type eCompress = boost::token_compress_off)
{
std::vector<std::string> toReturn;
boost::split(toReturn, Input, Pred, eCompress);
return toReturn;
}
Demo
关于c++ - 是否有 split_copy 或某种快捷方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54537601/