从位置删除多个单词

发布于 2025-01-25 12:07:39 字数 391 浏览 3 评论 0原文

定义

template <int... Positions> void removeWords (std::string& str);

将在位置上删除所有单词(令牌)位置...str。例如,

removeWords<1,3,8>(sentence);

将从句子中删除第一,第三和第8个单词。如何这样做,理想地使用C ++ 17倍表达式? pre c ++ 17,我们必须删除位置中的单词first,然后必须将REST的所有值降低...在使用之前再次,这是一团糟。

Define

template <int... Positions> void removeWords (std::string& str);

that will remove all the word (tokens) in the positions Positions... of str. For example,

removeWords<1,3,8>(sentence);

will remove the 1st, 3rd, and 8th words from sentence. How to do this, ideally using C++17 fold expressions? Pre C++17, we would have to remove the word in position First, then then would have to decrease all the values of Rest... by 1 before applying it again, which is a total mess.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文