【问题标题】:Boost equivalent of std::getline for boost::static_stringBoost 等效于 std::getline 的 boost::static_string
【发布时间】:2021-08-30 11:18:27
【问题描述】:

我正在将我的数据类型从 std::string 更改为 boost::static_string,因为我意识到当我在文件上写入时,使用 Boost 可以获得 8 秒,而使用 STL 则需要 25 秒。

我使用std::getline 来解析输入,但这显然与boost::static_string 不兼容。哪个是 std::getline 的 Boost 等效项,特别适用于 boost::static_string

【问题讨论】:

    标签: c++ string boost


    【解决方案1】:

    我使用 std::getline 来解析输入,但这显然与 boost::static_string 不兼容

    您可能会用istream::read 来表达它(需要char*, size_t)。

    用于解析输入

    在这种情况下,为什么不共享输入以便我们解决 XY 问题?对我来说,使用 iostreams 进行解析的代码对性能至关重要。

    • 50% 的机会您可以继续使用 std::getlinestd::string(并转换为 static_string),因为解析不在任何性能关键路径上
    • 50% 的机会真正的性能瓶颈在于解析,我很乐意向您展示替代方案(使用 Boost)

    【讨论】:

      猜你喜欢
      • 2014-02-02
      • 2020-11-17
      • 2013-06-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-12
      • 1970-01-01
      • 2017-03-11
      相关资源
      最近更新 更多