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.
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.
Live Example
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.
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.
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.
Related
The /std (Specify Language Standard Version) option is available in Visual Studio 2017 and later. Does it mean that previous versions of Visual Studio use particular versions of the C++ standard and, unlike gcc/clang, there's a 1:1 mapping between a VS version and the default C++ standard version provided by the compiler?
There is a blog post Standards version switches in the compiler that explains the introduction of the feature and what MSVC used to do previously:
Traditionally, we would release the compiler in a default mode that combines features striding several versions of the C++ language, e.g. C++98, C++03, C++11, C++14, etc. in addition to conformance improvement bug fixes. This can lead to situations where it is difficult to simultaneously upgrade to the newer and better compiler and at the same time move your code forward. We really appreciate the great feedback you’ve given us about our conformance improvements and new feature work. As the C++ standards committee is gearing up for a new C++ version, we’ve taken the initiative to help you state in your build systems or compiler command lines which version of C++ you are comfortable with while updating to the next version of Visual C++.
Visual C++ has made significant progress towards C++ standards conformance between the first release of Visual Studio 2015 and VS 2015 Update 3. We’ve fixed many issues with constexpr, improved expression SFINAE support, evaluation of initializer lists, variable templates, and more. Our standard library implementation has kept pace with features adopted into the post-C++14 standard draft. And we’ve implemented some major features currently under consideration by the committee, including C++ modules and coroutines. We want you to benefit from all this, but also we want you to consume these features at your own pace, while upgrading to this new update.
All post-C++14 features implemented in this update are off by default; those which were included in previous releases are left on to avoid causing your builds.
...
From what I gather /std:c++17 would be equivalent to clang/gcc -std=c++17 argument.
Some versions of msvc may not fully implement some versions of iso C++.
Depending on the Visual C++ compiler version or update level, certain C++14 or C++17 features may not be fully implemented or fully conformant when you specify the /std:c++14 or /std:c++17 options. For example, the Visual C++ 2017 RTM compiler does not fully support C++14-conformant constexpr, expression SFINAE, or 2-phase name lookup.
(cf: https://learn.microsoft.com/en-us/cpp/build/reference/std-specify-language-standard-version?view=vs-2017 )
So that's not exactly a "1:1 mapping between VS version and the default C++ standard version provided by the compiler".
You shouldn't rely on that.
Instead you should read the docs for the version of VS you're using.
Hope this answers your question.
First of all, C++17 changes are listed in this post. Today I downloaded clang to check if it was complete for C++17 (as gcc hasn't implemented everything yet), and here you can read:
Clang 5 and later implement all the features of the C++ 2017 Draft International Standard.
You can use Clang in C++17 mode with the -std=c++17 option (use -std=c++1z in Clang 4 and earlier).
Then, I assume that all features of C++17 have been added in clang 5.0, but checking all of them, I couldn't find the extensions for parallelism of stl algorithms and so on. I tried adding the header <execution> to test the new feature, but nothing seems to work.
I'm suspencting that this feature "maybe" won't be available, but I'm not sure because there's almost no information about it.
I think Intel implemented something in its compiler, but I'm not really into it since I use Linux.
Are extensions for parallelism going to be available for the new C++17 Standard?
Yes, extensions for parallelism have been merged into the ISO C++ Standard.
Clang 5 and later implement all the features of the C++ 2017 Draft International Standard.
This seems to refer only to core language features. You probably want to check the libc++ and/or libstdc++ conformance status instead.
https://libcxx.llvm.org/cxx1z_status.html
https://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html
In the above links, P0024 is not marked as implemented.
My compiler doesn't find #include <future> when I need to execute an Async Task. How can I include it properly? Can I download the headers and make a reference to them?
std::future is C++11 onwards.
Visual Studio 2005 does not support the C++11 and C++14 standards, so no.
(It barely gets the for scoping correct!)
Consider upgrading your toolchain, but note that VC2012 only partially supports C++11 features. You could try boost (www.boost.org). It contains material that's often accepted into future standards, so may well contain a future that can be compiled with VC2005.
I was happy see that map::at() was added to c++11, but upon digging around, I see that's it's already defined in gcc libraries, and works with -std=c++0x, and c++98.
Is using this method for code compiled with a standard before c++0x considered portable?
I think you are misinterpreting what -std=c++0x means. From C dialect options:
'c++11'
'c++0x'
The 2011 ISO C++ standard plus amendments. Support for C++11 is still experimental, and may change in incompatible ways in future
releases. The name 'c++0x' is deprecated.
As you can see c++0x and c++11 are equivalent and c++0x is deprecated.
What is the best compiler to experiment with C++0x features? I have been experimenting with GNU g++ 4.4.
Definitely GCC Trunk. ConceptGCC misses many features GCC trunk has. It is being merged into GCC currently though. It has all these features, including the new auto-typed variables (no new function declaration syntax yet though): http://gcc.gnu.org/projects/cxx0x.html .
There is a GCC branch containing partial lambda support, which also contains other C++0x features. I would recommend you to try that one out too. It's in use on #geordi at irc.freenode.org, you can experiment with it there.
Comeau - just for trying it online
ConceptGCC (wiki) was made for that purpose, if I am not mistaken.
It's probably not the best for C++0x experimentation, but for people who are MSVC oriented, there's a "Community Tech Preview" (CTP) of VS2010 which contains a preview of VC10 that has some parts of C++0x implemented (note that VC10 will not have the full set of C++0x changes implemented even when VC10 is released):
http://www.microsoft.com/downloads/details.aspx?FamilyId=922B4655-93D0-4476-BDA4-94CF5F8D4814&displaylang=en
Some details on what's new in the VC10 CTP:
Visual Studio 2010 CTP released
Lambdas, auto, and static_assert: C++0x Features in VC10, Part 1
As noted in the above article, "The Visual C++ compiler in the Microsoft Visual Studio 2010 September Community Technology Preview (CTP) contains support for four C++0x language features, namely:"
lambdas,
auto,
static_assert,
rvalue references