2
#include <vector>
#include <functional>

int main(int argc, char** argc)
{
    std::vector<int> x;
    std::function<void (void)> f(std::allocator_arg,x.get_allocator());
    return 1;
}

Using : g++ test.cpp -o test -std=c++11
It failed on Ubuntu 15, my g++ version is 5.2.1. it's all ok on XCode and VS2015. and I check /usr/include/c++/5/functional, it has no constructor for allocators. I check www.cplusplus.com, and It defines the constructor with allocator.
Someone can tell me how to fix this problem or I have to change the g++ stl, How to change g++ stl with other stl ? I have downloaded sgi stl source codes.
Please help ! Thanks a lot .

Praveen
  • 8,945
  • 4
  • 31
  • 49
NeoLiu
  • 212
  • 3
  • 11

1 Answers1

2

The use of allocator in std::function has many issues.

What's the point of std::function constructor with custom allocator but no other args?

http://cplusplus.github.io/LWG/lwg-closed.html#2386

http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0302r0.html

Looking at the g++ functional source, it obviously does not make use of any allocator construct for dynamic allocation, it plainly uses new and delete.

So, I am not sure how you can provide your allocator to do the heap allocation. But, one bad idea is to derive from function and overload the new and delete operator. I would suggest you to NOT to go down this path. It's a very very BAD idea.

Community
  • 1
  • 1
Arunmu
  • 6,837
  • 1
  • 24
  • 46