Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++17 support Eclipse Neon

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.

like image 657
chronosynclastic Avatar asked May 18 '17 09:05

chronosynclastic


2 Answers

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.

like image 74
Yakk - Adam Nevraumont Avatar answered Oct 18 '22 20:10

Yakk - Adam Nevraumont


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:

  • Let eclipse use c++1y (C++14) dialect, this is sufficient
  • Link libstdc++fs.a
  • Include <experimental/filesystem>
like image 1
King Thrushbeard Avatar answered Oct 18 '22 21:10

King Thrushbeard