2024 Update: Efficient and Reliable Wrapping of C APIs Using Modern C++
summary
Practical recipe for wrapping LMDB shows concrete techniques: use std::expected and std::span plus C++20/23 concepts to push errors and flags to compile time, bind readonly/open flags into distinct types so mutating methods disappear, manage C resources with RAII via unique_ptr with custom deleter and out_ptr helpers, and expose cursors as input iterators/ranges (exceptions required for error propagation). Tests use either link-time injection or compile-time proxy mocks; runtime overhead stays minimal because there is no dynamic dispatch or extra allocations.
AI-written summary · about
chapters (10)
- 0:00C API wrapping intro
- 6:52Why wrap C APIs
- 12:50Error handling in wrappers
- 22:50RAII for resources
- 28:11Compile-time wrapper config
- 35:18Adapting C++ to C APIs
- 46:27Advanced wrapper techniques
- 57:13Iterators for C API data
- 1:02:33Testing wrapper strategies
- 1:15:11Summary
related talks
56mEfficient and Reliable Wrapping of C APIs Using Modern C++
51mTypical C++, but Why?
59mModern C++ for Fun and Profit: This isn’t your old C++
01h 07mDesign Patterns in Modern C++
05mPostmodern Meta C++
56mCute C++ Tricks (and what you can learn from them): Part 2 of N
01h 36mBuilding C++ Interfaces That Are Hard to Use Incorrectly
54mTypical C++, But Why?
