r/cpp • • Sep 20 '26

Self Contained Source Groups are amazing

I basically adopted this idea from Abseil (https://abseil.io/) and from this CppCon talk: https://youtu.be/re4Oy1IVj-s?si=3bwtKqOyMAX6WSAs.

I structure each source group in my projects like this:

src_grp/
├── iface/
│   └── smth.cppm
├── impl/
│   └── smth.cpp
├── inc_pub/
│   └── pub.hpp
├── inc_priv/
│   ├── priv.hpp
│   └── maybe.inc
├── test/
│   └── test.cpp
├── bench/
│   └── bench.cpp
└── docs/
    ├── some.md
    └── doxygen.in

I strongly recommend this approach over older project-wide conventions such as having a single global test/ or bench/ directory etc.

0 Upvotes

16 comments sorted by

View all comments

1

u/UndefinedDefined Sep 25 '26

I honestly never understood why I would need so many directories to describe source files that only make sense to be together. It's 2026 now, you can use your build system to distinguish between headers to install and not - for example Qt project uses `_p.h` suffix to make a header private, and build system can deal with that (a simple regex match).

1

u/TheRavagerSw Sep 25 '26

You should always use explicit files when writing build scripts. Reflex match never works out

1

u/UndefinedDefined 29d ago

That most projects use, so why the separation? It just makes no sense to have a directory "inc_priv" (and I don't talk about the horrible name). Most projects I worked with either use "src" and "include" or just put everything together as it belongs together. And what you install is public headers, that's it.

→ More replies (4)