Код: Выделить всё
#include
#include
constexpr std::size_t ceil_to_multiple(std::size_t number, std::size_t multiple)
{
return number + multiple - 1 - (number + multiple - 1) % multiple;
}
template
struct shared_ptr_storage
{
constexpr static std::size_t align = std::max(alignof(void*), alignof(T));
constexpr static std::size_t size = ceil_to_multiple(sizeof(T), align) + 32;
std::array buffer;
};
template
struct shared_allocator;
template
struct shared_allocator_impl
{
using value_type = U;
shared_allocator_impl() = delete;
shared_allocator_impl(const shared_allocator&) {}
static_assert(sizeof(U) ~value_type();
}
template
struct rebind{
using other = std::conditional_t;
};
};
template
bool operator==(const shared_allocator&, const shared_allocator&) { return true; }
template
bool operator!=(const shared_allocator&, const shared_allocator&) { return false; }
template
bool operator==(const shared_allocator&, const shared_allocator_impl&) { return true; }
template
bool operator!=(const shared_allocator&, const shared_allocator_impl&) { return false; }
int main()
{
shared_allocator allocator;
auto i = std::allocate_shared(allocator, 10);
auto j = std::allocate_shared(allocator, 20);
}
Это нужно мне, чтобы я мог добавить дополнительные свойства вshared_ptr_storage и затем получить к ним доступ позже в конструкция().
Подробнее здесь: https://stackoverflow.com/questions/790 ... -construct