C++11 functionality with MinGW - c++

I try to use emplace() function for an unordered_map and compiler says that no such function exists.
I put -std=c+11 and it says cc1plus.exe: error: unrecognized command line option '-std=c+11'
Can i somehow use C++11 functionality with mingw?

From the GCC documentation
C++0x was the working name of a new ISO C++ standard, which was then
released in 2011 as C++11 and introduces a host of new features into
the standard C++ language and library. This project seeks to implement
new C++11 features in GCC and to make it one of the first compilers to
bring C++11 to C++ programmers.
C++11 features are available as part of the "mainline" GCC compiler in
the trunk of GCC's Subversion repository and in GCC 4.3 and later. To
enable C++0x support, add the command-line parameter -std=c++0x to
your g++ command line. Or, to enable GNU extensions in addition to
C++0x extensions, add -std=gnu++0x to your g++ command line. GCC 4.7
and later support -std=c++11 and -std=gnu++11 as well.
So, for gcc 4.3 through 4.6 use -std=c++0x, for later version use -std=c++11. Library support for map::emplace was added in gcc 4.8

Related

How do I make sure I am utilizing C++14?

I am trying to compile some c++ I got from a book I am going through, when I try to compile I get this warning followed by 5 related errors.
main.cpp:16:9: warning: variable templates are a C++14 extension
[- Wc++14-extensions]
int table<RecordType>::CAPACITY;
^
I have never given a thought to updating c++ or being certain of what version I am using. I am compiling this in a mac using g++.
You may enable it with -std=c++14 flag. However, your GCC version should support it in the first place. Till GCC 4.9.3, you could use -std=c++1y whereas since GCC 5.2, it supports c++14 flag as well. For more info, refer to this.
Pass the -std=c++14 flag. There are also older versions with partial C++14 support which don't support -std=c++14 yet; for these, pass the -std=c++1y flag.
You need to tell the compiler which version of the standard to compile to.
Try g++ -std=c++14.
While -std=c++14 that others are recommending will enable C++14 feature support, it will also disable a bunch of things that are enabled by default, including support for advanced POSIX APIs.
Unless you specifically want to disable G++ extensions, you should use -std=gnu++14 not -std=c++14

Difference between gcc compile options std=c++1y and std=c++14

I installed gcc 4.9.2. I compiled the program using the following command:
/root/gcc-4.9.2/bin/g++ -std=c++1y testing.cpp
Note that in addition to the option -std=c++1y, there is another option -std=c++14. Will the compiler work in the same way and generate exactly the same executable for both options?
C++ 14 is the latest ISO standard, and should be used unless you need some gcc non standard feature.
c++1y is a name that was used to refer to the c++14 standard before it was completed, so it is most likely adhering to a draft of the standard, but not the actual standard itself. There may be some minute differences between the two, but c++14 is the ISO standard.
In short, use c++14.
In case of gcc 4.9.2 mentioned by you there is no difference between c++14 and c++1y. But for the earlier gcc version, e.g. gcc 4.8.1 there is no c++14 option
g++: error: unrecognized command line option '-std=c++14'
because the year of standard acceptance was not known yet. In such cases using the -std=c++1y option is only solution to enable some parts of oncoming c++14 standard.

C++14 TS functionality and GCC 4.8

I would like to try some of the new features that will make it to the C++2014 revision like std::make_unique and the std::filesystem functionnalities. I use ubuntu 14.04 and GCC/G++ 4.8 (with libstdc++-4.8-dev installed), and the flag -std=c++1y set. But there is no std::make_unique when including <tr1/memory>, and no <experimental/...> headers.
What do I need to do to be able to use some of those new features ?
Thanks !
<tr1/memory> is not a C++14 standard header. You simply want <memory>. Same for <dynarray>.
However, neither are supported in GCC 4.8. You need to upgrade to GCC 4.9 or clang 5.
The GCC compiler support status for C++1y can be checked on the Language Features status page, and the library support on the Library Support status page.

Clang 3.1 and C++11 support status

From clang's C++11 support status website, http://clang.llvm.org/cxx_status.html , it says, "Initializer List" and "Lambda Expression" are all supported starting from version 3.1.
However, using LLVM/Clang trunk (3.2), compiling against initializer list and lambda expression will yield error messages.
Does anyone know if Clang >3.1 supports those features?
By default, clang++ will not enable the C++11 features - you have to pass an additional flag during compilation.
clang++ -std=c++11 [input files...]
Or
# enables some additional C++11 extensions GCC has
clang++ -std=gnu++11 [input files...]
Additionally, you can switch between using libstdc++ and Clang's own libc++, which are different implementations of the C++ standard library. libc++ in some cases might have a better implementation of the C++11 standard than your existing libstdc++ library.
# uses clang's C++ library in C++98 mode
clang++ -stdlib=libc++ [input] # uses clang's C++ library
# uses clang's C++ library and enables C++11 mode
clang++ -stdlib=libc++ -std=c++11 [input]
The latter is important if you're using Clang in an environment with an outdated version of libstdc++ (like Mac OSX), but note that the two C++ libraries are not compatible with each other, so you would have to rebuild any dependencies against libc++ if you were to use that.
The page at http://clang.llvm.org/cxx_status.html is confusing at best. Currently, the released 3.1 version does not support initializer lists or lambdas (so I've switched back to GCC 4.8 for the time being).
You can always check clang support for features using the __has__feature macro, according to the instructions here:
http://clang.llvm.org/docs/LanguageExtensions.html#checking_language_features
For example, __has_feature(cxx_generalized_initializers) or __has_feature(cxx_lambdas) will return true if those features are available and enabled.
Personally, I'm expecting those features to be ready by clang 4.0, which is expected to be released with the next Xcode (likely June 2012).
-- Edited to clarify the versions I've been testing -- clearly, clang versioning is more complex than I had realized.

How can I use C++ 11 features in Clang?

How can I use the latest C++ 11 features in Clang? What (sub)set of features is supported?
You will need clang 3.3 to use the most relevant feature set from C++ 11. Read C++ Support in Clang for the complete list of up-to-date supported features. Clang 3.3 is claimed to be C++11 feature complete.
Clang's command line is gcc-compatible so you have to enable C++11 support via the followinf command-line switch
-std=c++11
There is also a bunch of post-C++11 features (like decltype(auto), member initializers and aggregates) that are supported by Clang 3.3. Use this command line switch to enable them
-std=c++1y
Here is the always up to date list of features supported by clang:
http://clang.llvm.org/cxx_status.html
To activate C++11, you have to add -std=c++11 in your clang calls, like for gcc.
If you use an IDE that is clang-aware or gcc-aware, there is a specific project settings option available to do that.