C++ Async Tasks. Include "Future" trouble - c++

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.

Related

Visual Studio 2019 - force C++11 features only

I use Visual Studio 2019 for C++ development. Due to constraints of legacy systems that code will be deployed to, I am limited to using only C++11 language features (specifically GCC 4.8.5).
The default in VS2019 is C++14, which is obviously a super set of C++11. I can't see a way to specify C++11 only. This would be useful as a much faster way to see if I accidentally include newer C++ features than seeing things fail in the build system.
Is there any way to change this setting?
I am afraid it's not possible.
there is no plan to add a C++11 switch
Link: Standards version switches in the compiler
The compiler doesn't support standards options for C++98, C++03, or
C++11.
/Zc:__cplusplus

How to compile with VS2017 for an older C++ standard?

I am using Visual Studio 2017 and need to create code that is compatible to VS2008 (C++03 or C++98). Is there a switch to restrict MSVC to C++03 features?
I am using CMake and tried to set
set_property(TARGET tgt PROPERTY CXX_STANDARD 98)
But this seems only to make sure, that the compiler supports C++98 or newer.
Any solution, that checks if C++ code uses features that are newer than the features supported by VS2008 will work as well. I just need to make sure, that I do not accidentally use features that are too new.
MSVC only got the standard switch in one of the updates to VS2015 (Update 3 to be exact) which was more or less C++14 compliant, and as such there are only switches for standards starting with C++14 (plus a few later features that were already implemented at the time of the update). All older features are enabled unconditionally for backwards compatibility (and because of all the work required to retrofit already implemented features for previous standards for virtually no gain).
See this blog post for more information: https://devblogs.microsoft.com/cppblog/standards-version-switches-in-the-compiler/
Also, note that there were a lot of conformance improvements in newer versions of MSVC, so even with the std switches you could write code that wouldn't work or would behave differently on older compiler.
A better solution would be just to use VS2008 toolset from VS2017 visual studio, as explained here: https://devblogs.microsoft.com/cppblog/stuck-on-an-older-toolset-version-move-to-visual-studio-2015-without-upgrading-your-toolset/
That way you'll be certain your code compiles on the older toolset, while using up-to-date IDE.

The C++ standard versions vs Visual Studio versions

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.

Why stoi function is available in Visual Studio 2010

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.

how to check VS c++ standard version

I am a VS user and I wanna find out info regarding to the c++ standard i am using.
i wonder how i can find out if it is c++11 standard or c++98 standard.
MSVC is probably not going to have an updated __cplusplus until more or all of that standard's features are implemented. See the comments on this page for more information.
Instead, use the macros available in Boost.Config to test for specific features. For example, to test whether decltype is supported, you can use:
BOOST_NO_CXX11_DECLTYPE
This will be defined if the compiler does not support decltype. Depending on your version of VS vs. your version of Boost, this might not be 100% up to date. Be sure to check that Boost version for what is supported. As Boost 1.56.0 has had major delays, I am unsure what the current status of VS support is in 1.55.0, but 1.56.0 should arrive pretty soon and I would think it would fix any outstanding issues with recent VS versions.