/******************************************************************************
Online C++ Compiler.
Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.
*******************************************************************************/
#include <iostream>
#include <map>
#include <cstddef>
#include <memory>
template <class T>
struct custom_allocator {
typedef T value_type;
custom_allocator() noexcept {}
template <class U> custom_allocator (const custom_allocator<U>&) noexcept {}
T* allocate (std::size_t n) {
return static_cast<T*>(::operator new(n*sizeof(T)));
}
void deallocate (T* p, std::size_t n) { ::delete(p); }
};
template <class T, class U>
constexpr bool operator== (const custom_allocator<T>&, const custom_allocator<U>&) noexcept
{return true;}
template <class T, class U>
constexpr bool operator!= (const custom_allocator<T>&, const custom_allocator<U>&) noexcept
{return false;}
using namespace std;
void* operator new(std::size_t sz) {
std::printf("op new called, size = %zu\n",sz);
return std::malloc(sz);
}
int main(){
custom_allocator<int> alloc;
std::shared_ptr<int> foo = std::allocate_shared<int> (alloc,10);
std::shared_ptr<int> bar = std::make_shared<int> (10);
}