This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: [c++0x]: stoi, to_string
Hi,
> Hello, I would like to know if this is correct. I'm using a recent svn
> version of gcc (maybe 2 weeks ago or so):
>
>
> #include <string>
> #include <iostream>
>
>
> int main() {
> using namespace std;
>
>
> cout << stoi("0xff") << endl;
>
> cout << to_string(static_cast<long long>(10)) << endl;
> }
>
>
> In this program, stoi returns 0. Is this correct? I think it should
> throw an exception std::invalid_argument or interpret this as hex.
>
The implementation is straightforward, just uses strtol, per the CD
standard. Please have a look to the implementation in
ext/string_conversions.h. I think the way libstdc++ uses the underlying
strtol is correct, the remaining issues can only be due to
non-conforming behavior of the underlying strtol (like, to explain what
I mean, http://sources.redhat.com/bugzilla/show_bug.cgi?id=1765). Let me
know, anyway...
> It's my guess, anyway I haven't
> read what the standard says about it. And to_string causes ambiguity.
> Is this because of c++ overloading? Do I really need to cast? Thanks.
>
In this case really no doubt we are implementing the CD literally, three
overloads, for long long, unsigned long long, long double.
Paolo.