问题描述
我已经搜索过Google和SO,但感到惊讶的是没有看到AllocatorAwareContainer概念的Hello World示例。我正在寻找这样的东西:
template <typename T,typename Allocator>
class HeapValue { // Value semantics of one object on the heap.
public:
explicit HeapValue(const Allocator& alloc = Allocator()) noexcept;
explicit HeapValue(const T& value,const Allocator& alloc = Allocator());
HeapValue(const HeapValue&);
HeapValue(const HeapValue&,const Allocator&);
HeapValue(HeapValue&&);
HeapValue(HeapValue&&,const Allocator&);
~HeapValue();
HeapValue& operator=(const HeapValue&);
HeapValue& operator=(HeapValue&&);
reference operator*() { return *m_ptr; }
const_reference operator*() const { return *m_ptr; }
pointer operator*() { return m_ptr; }
const_pointer operator*() const { return m_ptr; }
explicit operator bool() const { return static_cast<bool>(m_ptr); }
private:
pointer m_ptr;
allocator_type m_alloc;
};
template <typename T>
using PMRHeapValue = HeapValue<T,std::pmr::polymorphic_allocator<T>>;
int main() {
std::byte buffer[64] = {}; // A small buffer on the stack
std::pmr::monotonic_buffer_resource pool{std::data(buffer),std::size(buffer)};
PMRHeapValue<std::pmr::vector<int>> opt(&pool);
opt->push_back(42); // The vector should be using the pool too,right?
return opt->size();
}
我可以尝试通过std::vector
的源进行钓鱼,但这似乎应该放在某个示例中。应该如何定义这组成员函数以正确支持AllocatorAwareContainer概念?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)