I have an unordered_map named nodes. It is declared as follows:
unordered_map<T,shared_ptr<Vertex<T>>> nodes
Vertex is a class declared as follows:
template<typename T>
struct Vertex {
Vertex(T pLabel) : label(pLabel) {};
void addEdge(T destination,int weight) {
edges[destination] = weight;
}
T label;
unordered_map<T, int> edges;
};
I have a method that accepts the unoredered_map of the vertices as follows.
template<typename T>
void getMinSpanningTree(unordered_map<T,shared_ptr<Vertex<T>>>& nodes, T first, int infinityMarker) {
cout << nodes.size() << endl;
if(nodes.size() == 0) {
return;
}
...
...
When I stop the execution in LLDB and type the following:
(lldb) expr nodes.size()
I get the following output:
(lldb) expr nodes.size()
error: Couldn't lookup symbols:
__ZNKSt3__113unordered_mapINS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEENS_10shared_ptrI6VertexIS6_EEENS_4hashIS6_EENS_8equal_toIS6_EENS4_INS_4pairIKS6_SA_EEEEE4sizeEv
So, I'm not sure how to make the debugger output the answer the correctly. standard output for the following lines, print 5 in the output console:
cout << nodes.size() << endl;
Here, is how I'm using the function and the classes:
int main(int argc, const char * argv[]) {
shared_ptr<Vertex<string>> v1 = make_shared<Vertex<string>>("V1");
shared_ptr<Vertex<string>> v2 = make_shared<Vertex<string>>("V2");
shared_ptr<Vertex<string>> v3 = make_shared<Vertex<string>>("V3");
shared_ptr<Vertex<string>> v4 = make_shared<Vertex<string>>("V4");
shared_ptr<Vertex<string>> v5 = make_shared<Vertex<string>>("V5");
v1->addEdge("V2", 1);
v1->addEdge("V3", 3);
v2->addEdge("V1", 1);
v2->addEdge("V3", 3);
v2->addEdge("V4", 6);
v3->addEdge("V1", 3);
v3->addEdge("V2", 3);
v3->addEdge("V4", 4);
v3->addEdge("V5", 2);
v5->addEdge("V2", 3);
unordered_map<string,shared_ptr<Vertex<string>>> vertices;
vertices[v1->label] = v1;
vertices[v2->label] = v2;
vertices[v3->label] = v3;
vertices[v4->label] = v4;
vertices[v5->label] = v5;
getMinSpanningTree(vertices,v1->label,numeric_limits<int>::max());
return 0;
}
Printing the nodes, seems to dump everything:
(std::__1::unordered_map<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::shared_ptr<Vertex<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >, std::__1::hash<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::equal_to<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, std::__1::allocator<std::__1::pair<const std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::shared_ptr<Vertex<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > > > >) $0 = size=5 {
[0] = {
__cc = {
first = "V5"
second = std::__1::shared_ptr<Vertex<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >::element_type @ 0x0000000100208c68 strong=2 weak=1 {
__ptr_ = 0x0000000100208c68
}
}
__nc = {
first = "V5"
second = std::__1::shared_ptr<Vertex<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >::element_type @ 0x0000000100208c68 strong=2 weak=1 {
__ptr_ = 0x0000000100208c68
}
}
}
[1] = {
__cc = {
first = "V4"
second = std::__1::shared_ptr<Vertex<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >::element_type @ 0x0000000100208748 strong=2 weak=1 {
__ptr_ = 0x0000000100208748
}
}
__nc = {
first = "V4"
second = std::__1::shared_ptr<Vertex<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >::element_type @ 0x0000000100208748 strong=2 weak=1 {
__ptr_ = 0x0000000100208748
}
}
}
[2] = {
__cc = {
first = "V2"
second = std::__1::shared_ptr<Vertex<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >::element_type @ 0x0000000100208c08 strong=2 weak=1 {
__ptr_ = 0x0000000100208c08
}
}
__nc = {
first = "V2"
second = std::__1::shared_ptr<Vertex<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >::element_type @ 0x0000000100208c08 strong=2 weak=1 {
__ptr_ = 0x0000000100208c08
}
}
}
[3] = {
__cc = {
first = "V3"
second = std::__1::shared_ptr<Vertex<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >::element_type @ 0x00000001002086e8 strong=2 weak=1 {
__ptr_ = 0x00000001002086e8
}
}
__nc = {
first = "V3"
second = std::__1::shared_ptr<Vertex<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >::element_type @ 0x00000001002086e8 strong=2 weak=1 {
__ptr_ = 0x00000001002086e8
}
}
}
[4] = {
__cc = {
first = "V1"
second = std::__1::shared_ptr<Vertex<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >::element_type @ 0x0000000100208ba8 strong=2 weak=1 {
__ptr_ = 0x0000000100208ba8
}
}
__nc = {
first = "V1"
second = std::__1::shared_ptr<Vertex<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >::element_type @ 0x0000000100208ba8 strong=2 weak=1 {
__ptr_ = 0x0000000100208ba8
}
}
}
}