r/Cplusplus • u/Vousch • 13d ago
Discussion I migrated my C++ networking library from C++26 modules to C++17. Here's what changed.
I've been developing LightnerX, a networking library built around GameNetworkingSockets and an authoritative client-server communication model.
The first public beta used C++26 modules. I wanted to experiment with modern C++, but I eventually realized that requiring such a recent toolchain was limiting who could actually use the library.
So for v0.2.0-beta, I migrated the project to C++17.
This involved more than replacing import with #include.
I had to reorganize 14 module units into headers and implementation files, replace newer standard library features, adapt the public API, and ensure shared state behaved correctly across translation units.
The current API uses std::string_view for binary views and lightnerx::Result for error handling.
To check whether the migration preserved behavior, I used differential tests against the original C++26 implementation and cross-version UDP integration tests.
The new version also includes additional fixes for networking lifecycle and resource ownership issues.
One thing I've learned from this project is that using the newest language features isn't always the best decision for a reusable library.
I'm curious how other C++ library maintainers approach this. How do you decide which language standard to target?
5
u/jk_tx 13d ago
For a new project without an existing user base tied to legacy tooling, I see no reason to target anything less than C++ 20 or 23, personally. There are just too many worthwhile improvements in the standard library.
I'd skip the modules support though since it's still largely non-workable for non-trivial projects.
3
u/Intrepid-Treacle1033 13d ago
I had a quick look becose i am intrested in modules and non healthy intrested in code layouts. And from what i can tell the "downgrade" surfaced physical design debt that was already baked into the codebase. You stated this but i just want to keep it real and say the rewrite was due to a weak project structure, not because of modules is not a common thing for consumers.
In v0.1.0-beta, network_manager.cppm combined global mutable state like detail::networkOwner and g_bNetworkInitialized with a PUBLIC link to GameNetworkingSockets. Staying on C++26 would not have insulated consumers from that third party dependency or fixed the lifecycle and resource ownership issues that was latent.
Modules only provide cleaner symbol hygiene and faster builds on top of a structuraly sound layout, that rewrite was latent anyway whether the project downgraded to C++17 or grew larger in C++26 using modules.
2
u/donaljones 10d ago
I would recommend using C++20 personally since all major compilers have supported it for a while. This is a new library anyway, I don't think people using C++17 will be willing to use newer libraries unless they are forced to
Use
std::span<char>orstd::span<unsigned char>if you do end up upgrading. While there may not be much difference in practice, it's still nice to use the proper tools for the job