Is there a C/C++ equivalent for Python's "__init__.py"?

No, there is no such feature in C++ itself. Nor it seems the typically used compilers support it. A feature similar to Python's modules is introduced in C++20: https://en.cppreference.com/w/cpp/language/modules

You may want to look at build systems like SCons or CMake which will allow you to implement some preprocessing before the actual C++ preprocessing/compilation. For example, you can use them to generate a header file including all the headers from a directory, or do anything more complicated if you really need it.

Please do take into consideration the last part of the last sentence: do you really need it? Usually code is much easier to maintain if all its dependencies are explicit. Having a header including "everything" will make it hard to track. One can imagine some valid reasons for breaking this rule of course, e.g. if these headers are generated as well and it's desirable to have an automated way of including all of them. Still, it's best if scope of such "magic" is self-contained and as small as possible.


Is there a C/C++ equivalent of this thing?

Not equivalent, but for header-only libraries, it is common practise to include an aggregate header, which is a header than includes other header files. For example, if we look at boost filesystem:

/mnt/e/Repository/filesystem/include/boost/
├── filesystem
│   ├── config.hpp
│   ├── convenience.hpp
│   ├── detail/
│   ├── directory.hpp
│   ├── exception.hpp
│   ├── file_status.hpp
│   ├── fstream.hpp
│   ├── operations.hpp
│   ├── path.hpp
│   ├── path_traits.hpp
│   └── string_file.hpp
└── filesystem.hpp **Aggregate header**

Contents of filesystem.hpp:

...
#  include <boost/filesystem/config.hpp>
#  include <boost/filesystem/path.hpp>
#  include <boost/filesystem/exception.hpp>
#  include <boost/filesystem/directory.hpp>
#  include <boost/filesystem/operations.hpp>
#  include <boost/filesystem/file_status.hpp>
#  include <boost/filesystem/convenience.hpp>
#  include <boost/filesystem/string_file.hpp>

...

Note that this does not behave the same as the __init__.py file, it is a convenience feature. You need only include the aggregate header, to access all of the functionality.

Tags:

Python

C++

C++11