Detect missing include files with c++ preprocessor?
Mark Oates

Is is possible to use a header guard or something similar to detect if a header file is present or not?

#ifndef FILESYSTEM_INCLUDE_FILE_WHATEVER
  // add custom implementation
#else
  #include <filesystem>
#endif

torhu

No, you have to use make or some other external tool to do it.

Mark Oates

Okie dokie. Thanks.

torhu

But you can still define macros that you can then check in your headers, like `gcc -DHAVE_THE_FILE=1 game.cpp` etc. Just in case you didn't know ;)

Polybios

You can use __has_include() since C++ 17.

torhu
Polybios said:

You can use __has_include() since C++ 17.

Cool. I've been following the development of C++, but never noticed that feature.

Mark Oates

Modern C++ has a lot of cool stuff. <filesystem> I really like. It's got some cool little conveniences like temp_directory_path, last_write_time.

I'm not a fan of the more permissive complex conventions. They seem to me to lead down the bad path of incompressible complexity.

As for __has_include(), that's awesome. I probably won't use that though. I should really figure out why <filesystem> isn't appearing on the other system rather than trying to patch around it.

torhu

Most likely they have older GCC installations. You could install Boost and use boost::filesystem (or whatever it's called), I think that's pretty much a drop-in replacement.

Polybios

Hmm... Just make C++ 17 (with its standard headers) a requirement? They will come over time anyway.

Thread #617998. Printed from Allegro.cc