---
title: "Interconverting std::function and copyable_function"
url: https://daily.dev/posts/interconverting-std-function-and-copyable-function-az8s7dlex
source_url: https://quuxplusone.github.io/blog/2026/07/26/function-explosion
type: article
source: "Arthur O'Dwyer"
published: 2026-07-26T17:36:22.683Z
updated: 2026-07-26T17:36:46.839Z
tags: ["c++"]
reading_time: 6
upvotes: 0
comments: 0
language: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Interconverting std::function and copyable_function

**[Arthur O'Dwyer](https://daily.dev/sources/quuxplusone)** · 6 min read · 0 upvotes · 0 comments

## Summary

C++26 introduced std::copyable_function to fix design flaws in std::function (const-correctness, exception on null call, bloated API). However, interconverting between std::function and copyable_function can silently create a 'linked list' of nested callable wrappers, causing O(n) invocation overhead and a logical memory leak after repeated round-trips. As of July 2026, libstdc++ (GCC 16) exhibits this bad behavior, while Microsoft STL avoids it for move_only_function. A benchmark demonstrates invocation time growing linearly with the number of conversions. The post also advises developers writing custom type-erased types to guard against the same wrapping pitfall via unit tests.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://quuxplusone.github.io/blog/2026/07/26/function-explosion>

## Similar posts on daily.dev

- [C\+\+26: More function wrappers](https://daily.dev/posts/c-26-more-function-wrappers-cysgmsfdt) · Sandor Dargo · 0 upvotes · 0 comments
- [The Cost Of a Closure in C](https://daily.dev/posts/the-cost-of-a-closure-in-c-8jkdqymxq) · The Pasture · 1 upvotes · 0 comments

---

Tags: [#c++](https://daily.dev/tags/c++)

[View this post on daily.dev](https://daily.dev/posts/interconverting-std-function-and-copyable-function-az8s7dlex)
