By Blog Staff | Jul 9, 2026 01:13 PM | Tags: None
C++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::functionsince C++11 andstd::move_only_functionsince C++23, but there were still missing pieces. Now we’re getting two new additions:std::copyable_functionandstd::function_ref.What’s wrong with
std::function?
std::functionhas 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.
0 Comments
Log in to join the conversation.No comments yet. Be the first to share your thoughts.