Pergunta

This open-std document suggests that std::function supports a custom allocator, however i can't find anything on the internet or the usual references as to how to provide that custom allocator.

My research tend to make me believe that the custom allocator is implemented in boost::function but did not make it to std::function yet.

So the question is does std::function suuport a custom allocator in C++11 ? If no will it most likely support one in C++14 ?

Foi útil?

Solução

std::functions has several constructors that you can pass std::allocator_arg as the first argument and an actual allocator as the second.

http://en.cppreference.com/w/cpp/utility/functional/function/function

Outras dicas

The standard says std::function supports a custom allocator but some compilers (at least GCC) do not support it yet. It's not entirely clear how custom allocators are supposed to work with std::function, or other class templates in the standard library that use type erasure, see e.g. LWG 2095 and LWG 2245. IMHO allocator support for these types is half-baked and not well specified.

N3726 proposes some changes that would clarify how std::function is supposed to use its allocator, as part of some much larger changes.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top