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.
Related
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.
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.
Quoting from the GCC page on C++14 support
Important: Because the final ISO C++14 standard was only recently published, GCC's support is experimental. No attempt will be made to maintain backward compatibility with implementations of C++14 features that do not reflect the final standard.
I could not find the official GCC definition of experimental. Does it only apply to backward compatibility wrt non-standard features, as the last sentence mentions? Or does it also indicate stability, or lack thereof? An earlier sentence on the same page says
C++14 features are available as part of the "mainline" GCC compiler in the trunk of GCC's Subversion repository and in GCC 4.8 and later.
To me, this suggests stability. Is this the case? In particular, my question is about GCC 4.9, since that is the earliest version with full C++14 support, according to the aforementioned page.
There is no "official GCC definition", only the official English definition.
The passage means that, where GCC previously implemented experimental prototypes of then-upcoming C++14 features before C++14 was published, future versions will not bother to try to maintain backward compatibility with those experiments.
Backward compatibility between two versions is only maintained with respect to features that were in an International Standard at the time that they were included in those versions.
This is because, prior to standard publication, the specification of new C++ features can change rather dramatically. It would be madness to guarantee that early experiments in support for them would be forwards compatible with the final, true feature as eventually published in a standard.
In short: use experimental features at your own risk and do not expect them to work the same way in the next version of GCC.
I am currently on RHEL 5.4 with gcc 4.1 installed, but I want to use unordered_map. As I found out, this is only introduced in C++11 to the standard, and therefore not available. One alternative would be using __gnu_cxx::hash_map, but I would prefer using standards.
On another development host I happend to have RHEL 6.4 and gcc 4.4, which knows unordered_map, but gives the following warning:
../include/c++/4.4.7/c++0x_warning.h:31:2: error: #error This file requires compiler and library support for the upcoming ISO C++ standard, C++0x. This support is currently experimental, and must be enabled with the -std=c++0x or -std=gnu++0x compiler options.
From the gcc homepage I can't seem to find out which gcc version supports unordered_map.
[edit]
To clarify my question:
I am stuck to several operating systems and their versions by customer requirements, therefore I cannot always update to the latest GCC version and be happy. I need to maintain compatibility of my software across all platforms.
I am therefore searching for the minimum GCC version required to use unordered_map. I am aware of the fact that supplying -std=c++0x to GCC fixes the error above, but I dont know how far the "experimental" warning means I should not be using unordered_map.
Some guys in this thread strongly advise not to use this experimental C++11 implementation
... so what should I do?
You cannot find such information on the GCC page. There is information about library features, but only about current version of GCC. In your GCC 4.4, you can simply use -std=c++0x flag to remove the warning.
If you are scared about experimental and cannot update the compiler - just don't use unordered_map from C++11. You can write your own, use one from tr1, or use the one from boost, no matter.
If you just look at GCC site - there is message there:
Important: GCC's support for C++11 is still experimental. Some
features were implemented based on early proposals, and no attempt
will be made to maintain backward compatibility when they are updated
to match the final C++11 standard.
By the way, all features of the C++11 standard are realized in GCC, it's actually old standard, since now C++14 is already approved, but support is still expiremental.
I have no idea WHY it's still experimental, for example on clang site:
Clang fully implements all published ISO C++ standards including
C++11, as well as the upcoming C++14 standard, and some parts of the
fledgling C++1z standard, and is considered a production-quality C++
compiler.
And only C++1z support is experimental.
You should upgrade to gcc 4.9.2, if you can. Otherwise use gcc 4.4. They'll both need the -std=c++0x option.
I'm new to c++ & I've this big confusion around c++ & g++ versions. I've come to understand that there are different version of g++ compiler, latest being 4.8 (i think). But then I see c++98 & c++11 mentioned at so many places. Are these two versioning systems for the same thing or is it for totally different things? And if they are different, how can I check if I'm using c++98 or c++11? Thanks!
C++98 and C++11 are standards rather than compilers. They are issued by ISO and compilers are expected to implement the features as given in the standards.
The g++ compiler is one that provides (as of 4.8 anyway) most of the features from the c++11 standard, as you can see here.