By Blog Staff | Jul 9, 2026 01:13 PM | Tags: None

SANDOR_DARGO_ROUND.JPGC++26 completes the type-erased callable wrapper picture. std::copyable_function gives us what std::function should have been from the start: a copyable wrapper with correct const semantics. std::function_ref fills the non-owning niche, offering a lightweight, zero-allocation alternative for callback parameters. Together with std::move_only_function, there’s no longer a reason to reach for std::function in new code.

C++26: More function wrappers

by Sandor Dargo

From the article:

C++26 continues to fill the gaps in our type-erased callable wrapper story. We already had std::function since C++11 and std::move_only_function since C++23, but there were still missing pieces. Now we’re getting two new additions: std::copyable_function and std::function_ref.

What’s wrong with std::function?

std::function has served us well, but it has two well-known issues. First, it can add significantly to binary size. Second, and more fundamentally, it has a const-correctness defect.