On 25 January 2014 16:00, Basile Starynkevitch wrote: > > First, my understanding of the C++11 standard thru > http://en.cppreference.com/w/cpp/utility/functional/function/function > (which I know is imperfect, but I find it much more readable than > n3337.pdf draft of C++11 ....) > is that in principle we should compile this code with the #if 0 replaced > by #if 1 (but we don't yet, our <functional> header says "TODO: needs > allocator_arg_t"). Perhaps the type of mygcalloc is wrong... > (I don't understand at all the issues of accepting allocators for > std::function)
Using allocators with std::function isn't supported yet. This is documented at http://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html#status.iso.2011 (and looking at the code, as you have done, should make it pretty clear the necessary constructors are not defined). > Then, I am surprised (and a bit disappointed) that (using GCC 4.8.2 from > Debian) with > > g++-4.8 -Wall -std=c++11 -O3 -S \ > -fdump-tree-phiopt -fverbose-asm testclogc.cc > > we are not inlining all the lambda stuff. I was expecting we'll do the > inlining, since similar experiments with std::array etc... That isn't similar and the use of std::array is irrelevant. std::function involves type erasure, usually dynamic allocation, and indirection through function pointers. If you don't use std::function then none of that needs to be optimised away.