Approaching closures in unmanaged languages: a comparison between C++, Rust, and Swift
When using lambdas in managed languages, the programmer does not need to concern themselves with the disposal of the closure; in contrast, unmanaged languages that implement lambdas need mechanisms to make the closures be disposed safely at the right time. Through examples, we explore and compare the following languages: C++, Rust, and Swift. For each language, we implement examples of the usage of lambdas in increasing complexity, analyzing how they work while showcasing the implementations. After presenting the implementations, we contrast the languages regarding memory safety and typing. Finally, from those experiments, we assess some properties of lambdas in the languages and summarize them in a table, namely: safety features, safe by default, safety guarantees, verbosity, type flexibility, and memory overhead.
Authors
- Luiz Romário Santana Rios
- Roberto Ierusalimschy (ORCID: https://orcid.org/0000-0003-2263-4955)
Institutions
- Pontifícia Universidade Católica do Rio de Janeiro (BR)
Publication Details
- Published
- 2025-09-22
- DOI
- https://doi.org/10.5753/sblp.2025.13162
- Primary Topic
- Model-Driven Software Engineering Techniques
- Type
- article
- Field-Weighted Citation Impact
- 0.00