From ed5757a3fd35d348915f4b1267e5232b04b250a8 Mon Sep 17 00:00:00 2001 From: Denes Matetelki Date: Sun, 12 May 2013 12:40:09 +0200 Subject: [PATCH] Working on allocators --- graph.hpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/graph.hpp b/graph.hpp index 1796d79..859ef07 100644 --- a/graph.hpp +++ b/graph.hpp @@ -185,7 +185,7 @@ private: struct Vertex { Vertex(const_reference data, Alloc allocator); - Vertex(const Vertex& o) : m_data(o.m_data), m_edges(o.m_edges), m_allocator(o.m_allocator) {} + Vertex(const Vertex& o); ~Vertex(); Vertex& operator=(Vertex o) { swap(o); return *this; } void swap(Vertex& o) { std::swap(m_data, o.m_data); std::swap(m_edges, o.m_edges); std::swap(m_allocator, o.m_allocator);} @@ -349,11 +349,21 @@ inline Graph::Vertex::Vertex(const_reference data, Alloc allocator) m_allocator.construct(m_data, data); } +template +inline Graph::Vertex::Vertex(const Vertex& o) + : m_data() + , m_edges(o.m_edges) + , m_allocator(o.m_allocator) +{ + m_data = m_allocator.allocate(1); + m_allocator.construct(m_data, *(o.m_data)); +} + template inline Graph::Vertex::~Vertex() { m_allocator.destroy(m_data); - m_allocator.deallocate(m_data, sizeof(V)); + m_allocator.deallocate(m_data, 1); } template