简体   繁体   中英

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

While investigating a strange tcmalloc error, my colleague and I traced the error to one line of code:

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()));

Everything worked just fine, as we changed it to:

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);

We got the tcmalloc error in the first version because the first code snippet wanted to allocate about 1.8GB at the point where this string is assembled in the parameter list and there was not enough memory available on the corresponding system. After we outsourced the assembly of the string as seen in the second code snippet this error did not occur anymore. Obviously, this string build from 2 integers and a single dot does not need anything near 1.8GB.

I would be very grateful if anyone could explain to me what exactly is going wrong. We suspect it has something to do with template deduction related to some black soci-libary magic, but are not sure.

As Jarod42 mentions, the problem is related to soci::use.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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