custom allocators: define missing 'rebind' type (#3895)

pull/3981/head
Sergei Trofimovich 2023-03-08 11:31:56 +00:00 committed by GitHub
parent b504dca35a
commit 6cec5aefc9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -20,11 +20,20 @@ struct bad_allocator : std::allocator<T>
{
using std::allocator<T>::allocator;
bad_allocator() = default;
template<class U> bad_allocator(const bad_allocator<U>& /*unused*/) { }
template<class... Args>
void construct(T* /*unused*/, Args&& ... /*unused*/)
{
throw std::bad_alloc();
}
template <class U>
struct rebind
{
using other = bad_allocator<U>;
};
};
} // namespace

View File

@ -189,6 +189,15 @@ class my_allocator : public std::allocator<T>
{
public:
using std::allocator<T>::allocator;
my_allocator() = default;
template<class U> my_allocator(const my_allocator<U>& /*unused*/) { }
template <class U>
struct rebind
{
using other = my_allocator<U>;
};
};
/////////////////////////////////////////////////////////////////////