Итак, могу ли я специализировать std::allocator для своих собственных типов? И если мне разрешено, нужно ли мне предоставить все члены основного шаблона std::allocator, учитывая, что многие из них могут быть предоставлены std::allocator_traits (и, следовательно, не рекомендуются в C++17)?
Рассмотрите эту программу
Код: Выделить всё
#include
#include
#include
#include
#include
#include
struct A { };
namespace std {
template
struct allocator {
using value_type = A;
using size_type = std::size_t;
using difference_type = std::ptrdiff_t;
using propagate_on_container_move_assignment = std::true_type;
allocator() = default;
template
allocator(const allocator&) noexcept {}
value_type* allocate(std::size_t n) {
if(std::numeric_limits::max()/sizeof(value_type) < n)
throw std::bad_array_new_length{};
std::cout
Подробнее здесь: [url]https://stackoverflow.com/questions/61151170/user-provided-stdallocator-specialization[/url]
Мобильная версия