C++26 introduces two new function wrappers: std::copyable_function and std::function_ref, addressing limitations in the existing std::function. The new additions provide better const-correctness and more flexible usage patterns, with std::copyable_function offering a const-correct alternative that supports copying, while std::function_ref provides a non-owning reference to callable objects.
Background
C++ has been evolving its support for type-erased callable wrappers since C++11's std::function, with C++23 adding std::move_only_function. However, there remained gaps in functionality, particularly around const-correctness and copyability.
- Source
- Lobsters
- Published
- May 20, 2026 at 10:52 PM
- Score
- 6.0 / 10