I read here that C++17 is feature-complete although the specifications are not completely ready yet. How can I use C++17 features in my code, especially in Eclipse CDT (Neon)?
Specifically, I would like to use the filesystem
to be able to iterate over directories easily.
Both libc++ and libstdc++ have a std::experimental::filesystem
in recent versions. I'm unaware of either having std::filesystem
directly; C++17 isn't released quite yet, that seems reasonable.
boost
has boost::filesystem
, which differs in a few ways but is structured nearly identically. Code written to use boost::filesystem
can be relatively easily ported to std::filesystem
.
As an example of an incompatibility, boost
has a singular flag enum, while std
has a plural flag enum bitfield with more settings.
You may have to pass -std=c++1z
to the compiler, check your libc++
or libstdc++
version, switch which one you are using, install a new one, etc. Or install boost, and use its filesystem library which C++17s was based off of.
Although std::filesystem
is scheduled to come with C++17, the current compiler implementations do not ship yet "official" C++17 support. As Yakk already stated in his answer, recent compiler and standard C++ library versions have std::experimental::filesystem
.
At least for the GNU compiler g++
I can say that you do not even need to set the C++17 language dialect, using C++14 is sufficient! However, you need to link the (static) library libstdc++fs.a
additionally.
Also, it is then quite convenient to define the std::filesystem
namespace, so that you can use the headers (nearly) as if they were finalized already:
// ...
#include <experimental/filesystem>
namespace std {
namespace filesystem = std::experimental::filesystem;
}
// now use std::filesystem ...
In summary:
libstdc++fs.a
<experimental/filesystem>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With