Skip to content

Commit

Permalink
custom allocators: define missing 'rebind' type (#3895)
Browse files Browse the repository at this point in the history
  • Loading branch information
trofi authored Mar 8, 2023
1 parent b504dca commit 6cec5ae
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions tests/src/unit-allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions tests/src/unit-regression2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
};
};

/////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 6cec5ae

Please sign in to comment.