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

Show parent comment

1

u/TheRavagerSw Sep 26 '26

You need to install private headers sometimes, for example when using C++ modules

1

u/UndefinedDefined Sep 26 '26

Then they are not private anymore.

0

u/TheRavagerSw Sep 26 '26

They are private, you need them when building your C++ module interface files, they don't get used by the end user.

1

u/UndefinedDefined Sep 26 '26

It makes no sense to call them private then. Private means the user doesn't need them, and doesn't need transitive dependencies these headers depend on.

Just don't call them private headers then. They are not private if user needs them for whatever reason.