#include #include #include #include using std::vector; using std::size_t; template struct mallocator : std::allocator { using value_type = T; T *allocate(size_t cnt) { std::printf("custom allocate called!\n"); return static_cast(std::malloc(cnt * sizeof(T))); } void deallocate(T *mem) { return std::free(mem); } void deallocate(T *mem, size_t) { return std::free(mem); } }; int main() { vector> foo = {1, 2, 3, 4, 5}; for (int i=0; i<10; i++) { foo.push_back(8); } } /////////////////////////////////////// $ g++ --version g++ (GCC) 8.2.0 Copyright (C) 2018 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ g++ -std=c++17 minimal_example.cc $ ./a.out $ $ clang++ --version clang version 6.0.0-1ubuntu2 (tags/RELEASE_600/final) Target: x86_64-pc-linux-gnu Thread model: posix InstalledDir: /usr/bin $ clang++ -std=c++17 minimal_example.cc $ ./a.out $ $ $ clang++ -std=c++17 -stdlib=libc++ minimal_example.cc $ ./a.out custom allocate called! custom allocate called! custom allocate called! $