[英]Why does GCC implement std::to_string using std::vsnprintf?
Recently, I looked into GCC's basic_string.h
and noticed that all std::to_string
overloads are implemented using std::vsnprintf
like for example:最近,我查看了 GCC 的basic_string.h
并注意到所有std::to_string
重载都是使用std::vsnprintf
实现的,例如:
inline string
to_string(int __val)
{
return __gnu_cxx::__to_xstring<string>(&std::vsnprintf, 4 * sizeof(int), "%d", __val);
}
Wouldn't this introduce a lot of overhead?这不会引入很多开销吗? Stringifying an integer base 10 is possible in just a few lines of code, so why would this be implemented using vsnprintf
?只需几行代码就可以将 integer 以 10 为基数进行字符串化,那么为什么要使用vsnprintf
来实现呢?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.