A Large-Scale Analysis of C++ Lambdas and Their Capture Lists in Opensource Repositories

  • Luiz Romário Santana Rios UFRJ
  • Hugo Musso Gualandi UFRJ

Resumo


In C++, lambda expressions offer fine control over variable capture: variables can be captured wholesale or individually, and they may be captured by value or by reference. This study is a large-scale analysis of C++ lambda variable capture patterns, aggregating data from over 1600 open-source repositories, since the release of lambdas in C++11. We are the first to measure the frequency of lambda expressions per lines of code, as opposed to total number of lambdas, and are the first to measure the frequency of different variable capture strategies. We confirm that lambda use in C++ is on a growing trend and it is in widespread use: over 70% of projects use lambdas. However, we observed that adoption of lambdas was a slow process; it was only in late 2019 that adoption reached 50%. We also observe substantial variety in variable capture strategies. Out of the repositories that used lambdas, 38.3% favored capturing no variables, 23.5% favored explicit capture, 26.1% favored automatic capture by reference, 8.6% favored capturing only the “this” pointer, and only 3.6% favored automatic capture by value. Overall, implicit capture was twice as popular as explicit capture lists.

Palavras-chave: Programming paradigms and styles, Programming language design and implementation, Run-time environments

Referências

Heidi Hokka, Felix Dobslaw, and Jonathan Bengtsson. 2021. Linking Developer Experience to Coding Style in Open-Source Repositories. In 2021 IEEE International Conference on Software Analysis, Evolution and Reengineering (SANER). 516–520. DOI: 10.1109/SANER50967.2021.00057

Jaakko Järvi and John Freeman. 2010. C++ lambda expressions and closures. Science of Computer Programming 75 (2010), 762–772. DOI: 10.1016/j.scico.2009.04.003

Donghoon Kim and Loc Ho. 2020. The Reaction of Open Source Projects to C++ Templates and Lambdas: An Empirical Replication Study. In International Conference on Software Engineering and Knowledge Engineering. [link]

Amit Levy, Michael P. Andersen, Bradford Campbell, David Culler, Prabal Dutta, Branden Ghena, Philip Levis, and Pat Pannuto. 2015. Ownership is theft: experiences building an embedded OS in rust. In Proceedings of the 8th Workshop on Programming Languages and Operating Systems (Monterey, California) (PLOS ’15). Association for Computing Machinery, New York, NY, USA, 21–26. DOI: 10.1145/2818302.2818306

Cristina V. Lopes, Petr Maj, Pedro Martins, Vaibhav Saini, Di Yang, Jakub Zitny, Hitesh Sajnani, and Jan Vitek. 2017. DéjàVu: a map of code duplicates on GitHub. Proc. ACM Program. Lang. 1, OOPSLA, Article 84 (Oct. 2017), 28 pages. DOI: 10.1145/3133908

Walter Lucas, Fausto Carvalho, Rafael Campos Nunes, Rodrigo Bonifácio, João Saraiva, and Paola Accioly. 2024. Embracing modern C++ features: An empirical assessment on the KDE community. Journal of Software: Evolution and Process 36, 5 (2024), e2605. DOI: 10.1002/smr.2605

Sebastian Nielebock, Robert Heumüller, and Frank Ortmeier. 2019. Programmers do not favor lambda expressions for concurrent object-oriented code. Empirical Software Engineering 24, 1 (01 Feb 2019), 103–138. DOI: 10.1007/s10664-018-9622-9

Luiz Rios and Roberto Ierusalimschy. 2025. Approaching closures in unmanaged languages: a comparison between C++, Rust, and Swift. In Anais do XXIX Simpósio Brasileiro de Linguagens de Programação (Recife/PE). SBC, Recife, PE, Brasil, 97–99. DOI: 10.5753/sblp.2025.13162

Luiz Romário Santana Rios and Hugo Musso Gualandi. 2026. A Large-Scale Analysis of C++ Lambdas and Their Capture Lists in Opensource Repositories: Artifacts for the SBLP 2026 Article. DOI: 10.17605/OSF.IO/A27VE

Luiz Romário Santana Rios and Roberto Ierusalimschy. 2019. A survey of function values in imperative programming languages. Master’s thesis. Pontifícia Universidade Católica do Rio de Janeiro. DOI: 10.17771/PUCRio.acad.47283

Shubham Sangle and Sandeep Muvva. 2019. On the use of lambda expressions in 760 open source Python projects. In Proceedings of the 2019 27th ACM Joint Meeting on European Software Engineering Conference and Symposium on the Foundations of Software Engineering (Tallinn, Estonia) (ESEC/FSE 2019). Association for Computing Machinery, New York, NY, USA, 1232–1234. DOI: 10.1145/3338906.3342499

Bjarne Stroustrup. Last edited in 2016. C++11 - the new ISO C++ standard. [link] Accessed in June 2nd, 2026.

Phillip Merlin Uesbeck, Andreas Stefik, Stefan Hanenberg, Jan Pedersen, and Patrick Daleiden. 2016. An empirical study on the impact of C++ lambdas and programmer experience. In Proceedings of the 38th International Conference on Software Engineering (Austin, Texas) (ICSE ’16). Association for Computing Machinery, New York, NY, USA, 760–771. DOI: 10.1145/2884781.2884849

Fabian Wolff, Aurel Bílý, Christoph Matheja, Peter Müller, and Alexander J. Summers. 2021. Modular specification and verification of closures in Rust. Proc. ACM Program. Lang. 5, OOPSLA, Article 145 (Oct. 2021), 29 pages. DOI: 10.1145/3485522
Publicado
08/09/2026
RIOS, Luiz Romário Santana; GUALANDI, Hugo Musso. A Large-Scale Analysis of C++ Lambdas and Their Capture Lists in Opensource Repositories. In: SIMPÓSIO BRASILEIRO DE LINGUAGENS DE PROGRAMAÇÃO (SBLP), 30. , 2026, São Paulo/SP. Anais [...]. Porto Alegre: Sociedade Brasileira de Computação, 2026 . p. 20-26. DOI: https://doi.org/10.5753/sblp.2026.27674.