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.
330 Impressions