This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: implementation & optimization of std::function with and without allocator
- From: Marc Glisse <marc dot glisse at inria dot fr>
- To: Jonathan Wakely <jwakely dot gcc at gmail dot com>
- Cc: "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>, Basile Starynkevitch <basile at starynkevitch dot net>
- Date: Sun, 26 Jan 2014 00:40:16 +0100 (CET)
- Subject: Re: implementation & optimization of std::function with and without allocator
- Authentication-results: sourceware.org; auth=none
- References: <1390665655 dot 18254 dot 19 dot camel at glinka dot lesours> <CAH6eHdSAiMQo4Su+K0q00nex2QHTEcg=_J6kLCbvZ1=2JNqjjQ at mail dot gmail dot com>
- Reply-to: "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
On Sat, 25 Jan 2014, Jonathan Wakely wrote:
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.
Indeed. But optimizing the code generated when std::function is used seems
a worthy goal to me.
#include <functional>
int f(int i){return i-1;}
int main(){
std::function<int(int)> h=f;
return h(1);
}
Simplifying this to just:
int main(){return 0;}
should be achievable (and clang manages it, using either libstdc++ or
libc++). Filing some new PRs may be in order, if there aren't already a
few about this.
--
Marc Glisse