gbdev / gbdev/rgbds

Features from C++23 or later

Open
#2,003 0 comments 0 reactions 0 assignees View on GitHub
refactoring
Dominant language
C++
Stars
1.6k
Forks
193
Avg merge
22h 17m
Merged PRs (30d)
26

Description

As of v1.0.3 in 2026, we build RGBDS as pedantic C++20, and support certain older platforms (e.g. the last two Ubuntu LTS releases, and Mac OS X 10.9 or even 10.4) that may not even have all those C++20 features available (such as `std::filesystem` prior to macOS 10.15). Depending on how future versions of RGBDS get developed, if we eventually require C++23, this issue is for tracking the way we could use its new features.

C++17:

- [ ] Use [`std::filesystem`](https://en.cppreference.com/cpp/filesystem) instead of various platform-specific file handling (e.g. `std::filesystem::path.replace_extension` instead of our own `replaceExtension` function in `src/gfx/main.cpp`). (See reverted #1235 and #1280.)

C++20:

- [ ] Use [`std::format`](https://en.cppreference.com/cpp/utility/format/format) inside variadic templates instead of `vfprintf` inside variadic functions (similar to Rust's `format!`). (See #1973.)
- [ ] Use [`std::bit_width`](https://en.cppreference.com/cpp/numeric/bit_width) instead of our own cross-platform `ctz` and `clz` functions in `include/helpers.hpp`.
- [ ] Use [`std::make_shared(size)`](https://en.cppreference.com/cpp/memory/shared_ptr/make_shared#:~:text=shared%5Fptr%3CT%3E%20make%5Fshared%28%20std%3A%3Asize%5Ft%20N%20%29%3B) instead of `std::shared_ptr(new char[size])` in `src/asm/lexer.cpp`.
- [ ] Use [implicit `[&]` capture](https://en.cppreference.com/cpp/20#:~:text=Simplifying%20implicit%20lambda%20capture) instead of explicit `[&mappingsV = mappings, &nbPalettesV = nbPalettes]` aliases in `src/gfx/process.cpp`.

C++23:

- [ ] Use [deducing `this`](https://en.cppreference.com/cpp/language/member_functions#Explicit_object_member_functions) instead of `const_cast` for `File::operator*` and `File::operator->` in `include/file.hpp`.
- [ ] Use [`std::print`/`std::println`](https://en.cppreference.com/cpp/io/print) instead of `printf`/`fprintf` for console output (similar to Rust's `println!`).
- [ ] Use [`std::unreachable`](https://en.cppreference.com/cpp/utility/unreachable) instead of our own cross-platform `unreachable_` macro in `include/helpers.hpp`.
- [ ] Use [`[[assume()]]`](https://en.cppreference.com/cpp/language/attributes/assume) instead of our own cross-platform `assume` macro in `include/helpers.hpp`.
- [ ] Use [`std::expected`](https://en.cppreference.com/cpp/utility/expected) instead of sentinel values or output parameters for errors (similar to Rust's `Result`).
- [ ] Use [`std::flat_map`](https://en.cppreference.com/cpp/container/flat_map) instead of our own `InsertionOrderedMap` in `include/itertools.hpp`, and evaluate its performance instead of some `std::map`s and `std::unordered_map`s.
- [ ] Evaluate the performance of [`std::flat_set`](https://en.cppreference.com/cpp/container/flat_set) instead of some `std::set`s and `std::unordered_set`s.
- [ ] Use `std::string`'s [`.contains`](https://en.cppreference.com/cpp/string/basic_string/contains) method instead of checking whether `.find` is `.end`.
- [ ] Look for opportunities to use `std::optional`'s [monadic](https://en.cppreference.com/cpp/utility/optional#Monadic_operations) `.and_then`, `.transform`, and `.or_else` methods if they would simplify or clarify the code (similar to Rust's `Option`).
- [ ] Use [`#elifdef`](https://thephd.dev/no-us-without-you-elifdef-elifndef-c-n2645) instead of `#elif defined` in `include/helpers.hpp`, and `#elifndef` instead of `#elif !defined` in `include/platform.hpp`.
- [ ] Use `continue_visiting_tiles:` (a [label at the end of a compound statement](https://en.cppreference.com/cpp/language/statements#:~:text=labels%20can%20also%20be%20used%20anywhere%20in%20compound%20statements)) instead of `continue_visiting_tiles:;` in `src/gfx/process.cpp`.

C++26:

- [ ] Use [``](https://cppreference.com/cpp/header/contracts) to ensure `pre`- and `post`-conditions and `contract_assert` instead of `assert`/`assume` or relying on comments.
- [ ] Evaluate the performance of [`std::hive`](https://cppreference.com/cpp/header/hive) instead of `std::deque` for containers requiring pointer stability that do not need `operator[]` indexing access. (See: [Daniel Lemire's testing](https://lemire.me/blog/2026/08/02/how-fast-is-c26s-stdhive/))
- [ ] Evaluate the performance of [`std::inplace_vector`](https://cppreference.com/cpp/header/inplace_vector) instead of some `std::array`s.
- [ ] Use [`std::text_encoding`](https://cppreference.com/cpp/header/text_encoding) instead of our vendored `extern/utf8decoder`.
- [ ] Use [``](https://cppreference.com/cpp/header/stdckdint.h)'s `ckd_add`, `ckd_sub`, and `ckd_mul` functions instead of delicate checks for whether addition, subtraction, or multiplication will overflow.

Contributor guide

Open the contributing guide

Research direction

This is a broad tracking issue rather than one self-contained change. Start by choosing a single checklist item and reading its named locations, such as include/helpers.hpp, src/asm/lexer.cpp, or include/file.hpp, along with the relevant C++ standard and platform constraints. Done means the selected modernization is implemented and supported-platform compatibility or performance is verified.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
tooling
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.