It would be great if the clever implementation of std::function presented on the following page could find its way into libstdc++. http://probablydance.com/2013/01/13/a-faster-implementation-of-stdfunction/ > The code is in the public domain (I want all library writers to start using it) > and here is a download link: http://dl.dropbox.com/u/27990997/function.h
I've only glanced at the code but it's good to see you support passing an Allocator to the constructor (though it should use std::allocator_traits to support C++11 allocators) I was thinking of making some big changes to our std::function for GCC 4.9 in order to support custom allocators.
I've uploaded a new version that uses std::allocator_traits. It's behind the same download link as before.
*** Bug 106871 has been marked as a duplicate of this bug. ***
As I just wrote on the duplicate bug: I've looked into this and I don't think it can be done without an ABI break. Objects constructed in old code compiled by an older GCC would still have a null pointer, so code compiled by a new GCC can't assume that the pointer is never null.