繁体   English   中英

在模板 function 的参数列表中构建 std::string 时类型推导错误

[英]Type Deduction Error when building std::string in parameter list of template function

在调查一个奇怪的 tcmalloc 错误时,我和我的同事将错误追溯到一行代码:

soci::session db;
...
db << "INSERT INTO `public.tablename` (..., ..., textvalue) VALUES ('...', '...', :1);",
  soci::use(std::to_string(someStruct.getUint32_t()) + "." + std::to_string(someStruct.getUint32_t()));

一切正常,因为我们将其更改为:

soci::session db;
...
std::string temp = std::to_string(someStruct.getUint32_t()) + "." + std::to_string(someStruct.getUint32_t());
db << "INSERT INTO `public.tablename` (..., ..., textvalue) VALUES ('...', '...', :1);",
  soci::use(temp);

我们在第一个版本中遇到了 tcmalloc 错误,因为第一个代码片段希望在参数列表中组装此字符串的位置分配大约 1.8GB,并且相应系统上没有足够的 memory 可用。 在我们将第二个代码片段中所见的字符串组装外包之后,这个错误就不再发生了。 显然,这个字符串由 2 个整数和一个点组成,不需要任何接近 1.8GB 的空间。

如果有人能向我解释到底出了什么问题,我将不胜感激。 我们怀疑它与一些黑色社会图书馆魔法相关的模板推论有关,但不确定。

正如 Jarod42 提到的,问题与 soci::use 有关。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM