Reputation: 526
I don't understand why the stoi function from < string > is available in Visual Studio 2010 ( Platform Toolset = v100 ) since from documentation says that is a C++11 feature.
Could somebody please help me understand this ?
I would like to use it with GCC 4.4.7 as well .... this is my original intent.
Upvotes: 1
Views: 1925
Reputation: 180640
C++11 was a draft way before 2011. Since stoi()
was going to make it into the standard many compilers already added it before C++11 was finalized. Using C++11 features before C++11 was finalized was experimental as things could change once the standard was ratified
Running
#include <iostream>
#include <string>
int main()
{
int foo = std::stoi("5");
}
On godbolt.org with GCC 4.4.7 and -std=c++0x
does compile so it looks like you are set to use it.
Upvotes: 2
Reputation: 310980
Usually the Standard is discussed long before its final version will be adopted. During the discussion such documents like Working Draft of the Standard are published.
Sometimes it is clear enough before adopting the final revision of the Standard that some features will be included in the Standard because there is an unanimity among the members of the C++ Standards Committees.
Upvotes: 1
Reputation: 29966
stoi
is not a language feature (though VS2010 already had some minimal support for some features of c++11), but a library function. It just so happened that MS compiler team has already implemented the function in their implementation of the standard library by that time.
Upvotes: 0
Reputation: 41474
Compilers are allowed to provide extensions and library functions which aren't part of the C++ standard they're targeting. While VC++ 2010 doesn't comply fully with the C++11 standard, it does support certain features which are in C++11 and aren't in C++98, such as auto
and static_assert
.
There's a certain amount of risk involved in using "forward-compatible" features like this, because the draft of the standard the compiler writers targeted might have changed after the compiler was released, but C++11 was getting pretty stable by 2010, and the specification of stoi
is almost certainly unchanged in the final standard from its implemention in VC++ 2010.
This page gives information on which VC++ versions support which C++11 features.
Upvotes: 1