c++ - 是否有 split_copy 或某种快捷方式

标签 c++ boost

有人知道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/

相关文章:

c++ - 如何使用 boost 二分法?

c++ - 检查 cin 结果 c++

C++ 模板化、静态分配的数组

c++ - 如何在 boost 图形库中使用 `randomize_property` 和捆绑属性图?

c++ - Boost Geometry最近的查询是否总是先按最小距离对结果进行排序?

c++ - 如何检查 SSL 套接字是否关闭(异步)

c++ - 共享内存中的 std::mutex 不工作

c++ - 显式实例化泛型结构的泛型成员函数

c++ - 如果不相等,比较和交换后返回对象?

c++ - Boost线程和FFmpeg : Such simple code gives me error C2064. 我做错了什么呀?