Commit 4c8a80b5 authored by Jeff Trull's avatar Jeff Trull

Remove boost::any wrapper around std::shared_ptr

std::shared_ptr provides a limited amount of type erasure natively
based on void* and the fact that it stores the original type in the
deleter. As a result, if you know the original type, you can call
std::static_pointer_cast and recover a legitimate shared_ptr of the
right type, very efficiently.

It looks like the use of boost::any in this code is:

1) to hide the pointed-to type so a uniform container can be used
2) to represent "no pointer"

both of which can be handled natively by shared_ptr<void> with a small
performance gain from removing one indirection.
parent 46993132
......@@ -150,7 +150,7 @@ public:
// Gets the encapsulated graph view. See graph_filtering.cc for details
boost::any get_graph_view() const;
std::vector<boost::any>& get_graph_views() {return _graph_views;}
std::vector<std::shared_ptr<void>>& get_graph_views() {return _graph_views;}
private:
......@@ -168,7 +168,7 @@ private:
edge_index_map_t _edge_index;
// this will hold an instance of the graph views at run time
std::vector<boost::any> _graph_views;
std::vector<std::shared_ptr<void>> _graph_views;
// reverse and directed states
bool _reversed;
......
......@@ -524,17 +524,15 @@ retrieve_graph_view(GraphInterface& gi, Graph& init)
auto& graph_views = gi.get_graph_views();
if (index >= graph_views.size())
graph_views.resize(index + 1);
boost::any& gview = graph_views[index];
std::shared_ptr<g_t>* gptr = boost::any_cast<std::shared_ptr<g_t>>(&gview);
if (gptr == 0)
std::shared_ptr<void>& gview = graph_views[index];
if (!gview)
{
std::shared_ptr<g_t> new_g =
get_graph_ptr<g_t>(gi, init,
std::is_same<g_t, GraphInterface::multigraph_t>());
gview = new_g;
return new_g;
}
return *gptr;
return std::static_pointer_cast<g_t>(gview);
}
} //graph_tool namespace
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment