Commit 7fb5d71d authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Dump lambda::bind in favor of boost::bind

This is a large commit which replaces lambda::bind with boost::bind in
most parts of the code. This improves compilation time, and slightly
decreases compilation memory usage in some cases.
parent a89e069c
...@@ -16,20 +16,16 @@ ...@@ -16,20 +16,16 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <iostream> #include <iostream>
#include <boost/lambda/lambda.hpp>
#include <boost/lambda/bind.hpp>
#include <unistd.h> /* standard unix functions, like getpid() */
#include <sys/types.h> /* various type definitions, like pid_t */
#include <signal.h> /* signal name macros, and the signal() prototype */
#include "graph.hh" #include "graph.hh"
#include "graph_filtering.hh" #include "graph_filtering.hh"
#include "graph_properties.hh" #include "graph_properties.hh"
#include <boost/lambda/lambda.hpp>
#include <boost/lambda/bind.hpp>
using namespace std; using namespace std;
using namespace boost; using namespace boost;
using namespace boost::lambda;
using namespace graph_tool; using namespace graph_tool;
...@@ -64,9 +60,11 @@ size_t GraphInterface::GetNumberOfVertices() ...@@ -64,9 +60,11 @@ size_t GraphInterface::GetNumberOfVertices()
{ {
size_t n = 0; size_t n = 0;
if (IsVertexFilterActive()) if (IsVertexFilterActive())
run_action<>()(*this, var(n)=bind<size_t>(HardNumVertices(),_1))(); run_action<>()(*this, lambda::var(n) =
lambda::bind<size_t>(HardNumVertices(),lambda::_1))();
else else
run_action<>()(*this, var(n)=bind<size_t>(SoftNumVertices(),_1))(); run_action<>()(*this, lambda::var(n) =
lambda::bind<size_t>(SoftNumVertices(),lambda::_1))();
return n; return n;
} }
...@@ -75,9 +73,11 @@ size_t GraphInterface::GetNumberOfVertices() ...@@ -75,9 +73,11 @@ size_t GraphInterface::GetNumberOfVertices()
// linear complexity, since num_edges() is O(E) in Boost's adjacency_list // linear complexity, since num_edges() is O(E) in Boost's adjacency_list
size_t GraphInterface::GetNumberOfEdges() size_t GraphInterface::GetNumberOfEdges()
{ {
using namespace boost::lambda;
size_t n = 0; size_t n = 0;
if (IsEdgeFilterActive() || IsVertexFilterActive()) if (IsEdgeFilterActive() || IsVertexFilterActive())
run_action<>()(*this, var(n)=bind<size_t>(HardNumEdges(),_1))(); run_action<>()(*this, lambda::var(n) =
lambda::bind<size_t>(HardNumEdges(),lambda::_1))();
else else
n = _nedges; n = _nedges;
return n; return n;
......
...@@ -25,8 +25,6 @@ ...@@ -25,8 +25,6 @@
#include "fast_vector_property_map.hh" #include "fast_vector_property_map.hh"
#include <boost/dynamic_property_map.hpp> #include <boost/dynamic_property_map.hpp>
#include <boost/lambda/lambda.hpp>
#include <boost/lambda/bind.hpp>
#include <boost/variant.hpp> #include <boost/variant.hpp>
#include <boost/python/object.hpp> #include <boost/python/object.hpp>
#include <boost/python/dict.hpp> #include <boost/python/dict.hpp>
......
...@@ -288,8 +288,7 @@ struct graph_type_name ...@@ -288,8 +288,7 @@ struct graph_type_name
string get_graph_type(GraphInterface& g) string get_graph_type(GraphInterface& g)
{ {
string name; string name;
run_action<>()(g, lambda::bind<void>(graph_type_name(), lambda::_1, run_action<>()(g, bind<void>(graph_type_name(), _1, ref(name)))();
lambda::var(name)))();
return name; return name;
} }
......
...@@ -15,8 +15,6 @@ ...@@ -15,8 +15,6 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <boost/lambda/lambda.hpp>
#include <boost/lambda/bind.hpp>
#include <boost/mpl/contains.hpp> #include <boost/mpl/contains.hpp>
#include <boost/python/extract.hpp> #include <boost/python/extract.hpp>
...@@ -26,7 +24,6 @@ ...@@ -26,7 +24,6 @@
using namespace std; using namespace std;
using namespace boost; using namespace boost;
using namespace boost::lambda;
using namespace graph_tool; using namespace graph_tool;
struct graph_copy struct graph_copy
......
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
#include <boost/iostreams/filter/bzip2.hpp> #include <boost/iostreams/filter/bzip2.hpp>
#include <boost/iostreams/device/file_descriptor.hpp> #include <boost/iostreams/device/file_descriptor.hpp>
#include <boost/iostreams/device/file.hpp> #include <boost/iostreams/device/file.hpp>
#include <boost/lambda/bind.hpp>
#include <boost/graph/graphml.hpp> #include <boost/graph/graphml.hpp>
#include <boost/graph/graphviz.hpp> #include <boost/graph/graphviz.hpp>
#include <boost/python/extract.hpp> #include <boost/python/extract.hpp>
...@@ -38,7 +37,6 @@ ...@@ -38,7 +37,6 @@
using namespace std; using namespace std;
using namespace boost; using namespace boost;
using namespace boost::lambda;
using namespace graph_tool; using namespace graph_tool;
// //
...@@ -262,10 +260,9 @@ template <class IndexMap> ...@@ -262,10 +260,9 @@ template <class IndexMap>
python::object find_property_map(dynamic_property_map* map, IndexMap) python::object find_property_map(dynamic_property_map* map, IndexMap)
{ {
python::object pmap; python::object pmap;
mpl::for_each<value_types>(lambda::bind<void>(get_python_property(), mpl::for_each<value_types>(bind<void>(get_python_property(),
lambda::_1, _1, IndexMap(), ref(map),
IndexMap(), lambda::var(map), ref(pmap)));
lambda::var(pmap)));
return pmap; return pmap;
} }
...@@ -669,25 +666,20 @@ void GraphInterface::WriteToFile(string file, python::object pfile, ...@@ -669,25 +666,20 @@ void GraphInterface::WriteToFile(string file, python::object pfile,
typedef tr1::unordered_map<vertex_t, size_t> map_t; typedef tr1::unordered_map<vertex_t, size_t> map_t;
map_t vertex_to_index; map_t vertex_to_index;
associative_property_map<map_t> index_map(vertex_to_index); associative_property_map<map_t> index_map(vertex_to_index);
run_action<>()(*this, lambda::bind<void>(generate_index(), run_action<>()(*this, bind<void>(generate_index(),
lambda::_1, _1, index_map))();
index_map))();
if (graphviz) if (graphviz)
graphviz_insert_index(dp, index_map); graphviz_insert_index(dp, index_map);
if (GetDirected()) if (GetDirected())
run_action<detail::always_directed>() run_action<detail::always_directed>()
(*this, lambda::bind<void>(write_to_file(), (*this, bind<void>(write_to_file(), ref(stream), _1,
lambda::var(stream), index_map, ref(dp), graphviz))();
lambda::_1,
index_map, lambda::var(dp),
graphviz))();
else else
run_action<detail::never_directed>() run_action<detail::never_directed>()
(*this,lambda::bind<void>(write_to_file_fake_undir(), (*this,bind<void>(write_to_file_fake_undir(),
lambda::var(stream), ref(stream), _1, index_map,
lambda::_1, index_map, ref(dp), graphviz))();
lambda::var(dp), graphviz))();
} }
else else
{ {
...@@ -696,18 +688,13 @@ void GraphInterface::WriteToFile(string file, python::object pfile, ...@@ -696,18 +688,13 @@ void GraphInterface::WriteToFile(string file, python::object pfile,
if (GetDirected()) if (GetDirected())
run_action<detail::always_directed>() run_action<detail::always_directed>()
(*this, lambda::bind<void>(write_to_file(), (*this, bind<void>(write_to_file(), ref(stream), _1,
lambda::var(stream), _vertex_index, ref(dp), graphviz))();
lambda::_1, _vertex_index,
lambda::var(dp),
graphviz))();
else else
run_action<detail::never_directed>() run_action<detail::never_directed>()
(*this,lambda::bind<void>(write_to_file_fake_undir(), (*this,bind<void>(write_to_file_fake_undir(),
lambda::var(stream), ref(stream), _1, _vertex_index,
lambda::_1, _vertex_index, ref(dp), graphviz))();
lambda::var(dp),
graphviz))();
} }
stream.reset(); stream.reset();
} }
......
...@@ -20,12 +20,10 @@ ...@@ -20,12 +20,10 @@
#include "graph_selectors.hh" #include "graph_selectors.hh"
#include "graph_util.hh" #include "graph_util.hh"
#include <boost/lambda/bind.hpp>
#include <boost/mpl/for_each.hpp> #include <boost/mpl/for_each.hpp>
using namespace std; using namespace std;
using namespace boost; using namespace boost;
using namespace boost::lambda;
using namespace graph_tool; using namespace graph_tool;
namespace graph_tool namespace graph_tool
...@@ -61,8 +59,8 @@ void GraphInterface::ShiftVertexProperty(boost::any prop, size_t index) const ...@@ -61,8 +59,8 @@ void GraphInterface::ShiftVertexProperty(boost::any prop, size_t index) const
{ {
bool found = false; bool found = false;
mpl::for_each<writable_vertex_properties> mpl::for_each<writable_vertex_properties>
(lambda::bind<void>(shift_vertex_property(), _1, var(_mg), (bind<void>(shift_vertex_property(), _1, ref(_mg),
prop, index, var(found))); prop, index, ref(found)));
if (!found) if (!found)
throw GraphException("invalid writable property map"); throw GraphException("invalid writable property map");
} }
......
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
#include <boost/mpl/for_each.hpp> #include <boost/mpl/for_each.hpp>
#include <boost/mpl/transform.hpp> #include <boost/mpl/transform.hpp>
#include <boost/mpl/find.hpp> #include <boost/mpl/find.hpp>
#include <boost/lambda/bind.hpp> #include <boost/bind.hpp>
#include "graph.hh" #include "graph.hh"
...@@ -185,20 +185,18 @@ public: ...@@ -185,20 +185,18 @@ public:
{ {
if (_all_names.empty()) if (_all_names.empty())
{ {
using namespace lambda;
mpl::for_each<TypeSequence> mpl::for_each<TypeSequence>
(lambda::bind<void>(get_all_names(), lambda::_1, (bind<void>(get_all_names(), _1,
var(_type_names), var(_all_names))); ref(_type_names), ref(_all_names)));
} }
} }
const string& operator()(const type_info& type) const const string& operator()(const type_info& type) const
{ {
using namespace lambda;
string* name; string* name;
mpl::for_each<TypeSequence> mpl::for_each<TypeSequence>
(lambda::bind<void>(find_name(), lambda::_1, var(type), (bind<void>(find_name(), _1, ref(type),
var(_all_names), var(name))); ref(_all_names), ref(name)));
return *name; return *name;
} }
...@@ -262,8 +260,7 @@ public: ...@@ -262,8 +260,7 @@ public:
{ {
ValueConverter* converter = 0; ValueConverter* converter = 0;
mpl::for_each<PropertyTypes> mpl::for_each<PropertyTypes>
(lambda::bind<void>(choose_converter(), lambda::_1, (bind<void>(choose_converter(), _1, ref(pmap), ref(converter)));
lambda::var(pmap), lambda::var(converter)));
if (converter == 0) if (converter == 0)
throw bad_lexical_cast(); throw bad_lexical_cast();
else else
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
#include "graph_python_interface.hh" #include "graph_python_interface.hh"
#include <boost/python.hpp> #include <boost/python.hpp>
#include <boost/lambda/bind.hpp>
#include <set> #include <set>
using namespace std; using namespace std;
...@@ -44,9 +43,9 @@ GraphInterface::Vertices() const ...@@ -44,9 +43,9 @@ GraphInterface::Vertices() const
{ {
python::object iter; python::object iter;
run_action<>()(const_cast<GraphInterface&>(*this), run_action<>()(const_cast<GraphInterface&>(*this),
lambda::bind<void>(get_vertex_iterator(), lambda::_1, bind<void>(get_vertex_iterator(), _1,
lambda::var(const_cast<GraphInterface&>(*this)), ref(const_cast<GraphInterface&>(*this)),
lambda::var(iter)))(); ref(iter)))();
return iter; return iter;
} }
...@@ -89,14 +88,14 @@ GraphInterface::Vertex(size_t i) const ...@@ -89,14 +88,14 @@ GraphInterface::Vertex(size_t i) const
python::object v; python::object v;
if (IsVertexFilterActive()) if (IsVertexFilterActive())
run_action<>()(const_cast<GraphInterface&>(*this), run_action<>()(const_cast<GraphInterface&>(*this),
lambda::bind<void>(get_vertex_hard(), lambda::_1, bind<void>(get_vertex_hard(), _1,
lambda::var(const_cast<GraphInterface&>(*this)), ref(const_cast<GraphInterface&>(*this)),
i, lambda::var(v)))(); i, ref(v)))();
else else
run_action<>()(const_cast<GraphInterface&>(*this), run_action<>()(const_cast<GraphInterface&>(*this),
lambda::bind<void>(get_vertex_soft(), lambda::_1, bind<void>(get_vertex_soft(), _1,
lambda::var(const_cast<GraphInterface&>(*this)), i, ref(const_cast<GraphInterface&>(*this)), i,
lambda::var(v)))(); ref(v)))();
return v; return v;
} }
...@@ -117,9 +116,9 @@ GraphInterface::Edges() const ...@@ -117,9 +116,9 @@ GraphInterface::Edges() const
{ {
python::object iter; python::object iter;
run_action<>()(const_cast<GraphInterface&>(*this), run_action<>()(const_cast<GraphInterface&>(*this),
lambda::bind<void>(get_edge_iterator(), lambda::_1, bind<void>(get_edge_iterator(), _1,
lambda::var(const_cast<GraphInterface&>(*this)), ref(const_cast<GraphInterface&>(*this)),
lambda::var(iter)))(); ref(iter)))();
return iter; return iter;
} }
...@@ -193,10 +192,10 @@ python::object GraphInterface::AddEdge(const python::object& s, ...@@ -193,10 +192,10 @@ python::object GraphInterface::AddEdge(const python::object& s,
src.CheckValid(); src.CheckValid();
tgt.CheckValid(); tgt.CheckValid();
python::object new_e; python::object new_e;
run_action<>()(*this, lambda::bind<void>(add_new_edge(), lambda::_1, run_action<>()(*this, bind<void>(add_new_edge(), _1,
lambda::var(*this), src, tgt, ref(*this), src, tgt,
_edge_index, _edge_index,
lambda::var(new_e)))(); ref(new_e)))();
return new_e; return new_e;
} }
...@@ -221,9 +220,9 @@ void GraphInterface::RemoveEdge(const python::object& e) ...@@ -221,9 +220,9 @@ void GraphInterface::RemoveEdge(const python::object& e)
edge_t de; edge_t de;
bool found = false; bool found = false;
run_action<>()(*this, run_action<>()(*this,
lambda::bind<void>(get_edge_descriptor(), lambda::_1, bind<void>(get_edge_descriptor(), _1,
lambda::var(e), lambda::var(de), ref(e), ref(de),
lambda::var(found)))(); ref(found)))();
if (!found) if (!found)
throw ValueException("invalid edge descriptor"); throw ValueException("invalid edge descriptor");
RemoveEdgeIndex(de); RemoveEdgeIndex(de);
...@@ -283,16 +282,16 @@ python::object GraphInterface::DegreeMap(string deg) const ...@@ -283,16 +282,16 @@ python::object GraphInterface::DegreeMap(string deg) const
if (deg == "in") if (deg == "in")
run_action<>()(const_cast<GraphInterface&>(*this), run_action<>()(const_cast<GraphInterface&>(*this),
lambda::bind<void>(get_degree_map(), lambda::_1, bind<void>(get_degree_map(), _1,
deg_map, in_degreeS()))(); deg_map, in_degreeS()))();
else if (deg == "out") else if (deg == "out")
run_action<>()(const_cast<GraphInterface&>(*this), run_action<>()(const_cast<GraphInterface&>(*this),
lambda::bind<void>(get_degree_map(), lambda::_1, bind<void>(get_degree_map(), _1,
deg_map, out_degreeS()))(); deg_map, out_degreeS()))();
else if (deg == "total") else if (deg == "total")
run_action<>()(const_cast<GraphInterface&>(*this), run_action<>()(const_cast<GraphInterface&>(*this),
lambda::bind<void>(get_degree_map(), lambda::_1, bind<void>(get_degree_map(), _1,
deg_map, total_degreeS()))(); deg_map, total_degreeS()))();
return python::object(PythonPropertyMap<map_t>(deg_map)); return python::object(PythonPropertyMap<map_t>(deg_map));
} }
...@@ -408,9 +407,8 @@ void GraphInterface::ExportPythonInterface() const ...@@ -408,9 +407,8 @@ void GraphInterface::ExportPythonInterface() const
set<string> v_iterators; set<string> v_iterators;
typedef mpl::transform<graph_tool::detail::all_graph_views, typedef mpl::transform<graph_tool::detail::all_graph_views,
mpl::quote1<add_pointer> >::type graph_views; mpl::quote1<add_pointer> >::type graph_views;
mpl::for_each<graph_views>(lambda::bind<void>(export_python_interface(), mpl::for_each<graph_views>(bind<void>(export_python_interface(),
lambda::_1, _1,ref(v_iterators)));
lambda::var(v_iterators)));
export_python_properties(const_cast<GraphInterface&>(*this)); export_python_properties(const_cast<GraphInterface&>(*this));
def("new_vertex_property", def("new_vertex_property",
&new_property<GraphInterface::vertex_index_map_t>); &new_property<GraphInterface::vertex_index_map_t>);
......
...@@ -18,7 +18,6 @@ ...@@ -18,7 +18,6 @@
#ifndef PYTHON_INTERFACE_HH #ifndef PYTHON_INTERFACE_HH
#define PYTHON_INTERFACE_HH #define PYTHON_INTERFACE_HH
#include <boost/lambda/bind.hpp>
#include <boost/graph/graph_traits.hpp> #include <boost/graph/graph_traits.hpp>
#include <boost/mpl/logical.hpp> #include <boost/mpl/logical.hpp>
#include <boost/functional/hash.hpp> #include <boost/functional/hash.hpp>
...@@ -117,9 +116,9 @@ public: ...@@ -117,9 +116,9 @@ public:
{ {
CheckValid(); CheckValid();
size_t in_deg; size_t in_deg;
run_action<>()(_gi,lambda::bind<void>(get_degree<in_degreeS>(), run_action<>()(_gi, bind<void>(get_degree<in_degreeS>(),
lambda::_1, _v, _1, _v,
lambda::var(in_deg)))(); ref(in_deg)))();
return in_deg; return in_deg;
} }
...@@ -127,9 +126,8 @@ public: ...@@ -127,9 +126,8 @@ public:
{ {
CheckValid(); CheckValid();
size_t out_deg; size_t out_deg;
run_action<>()(_gi,lambda::bind<void>(get_degree<out_degreeS>(), run_action<>()(_gi, bind<void>(get_degree<out_degreeS>(), _1, _v,
lambda::_1, _v, ref(out_deg)))();
lambda::var(out_deg)))();
return out_deg; return out_deg;
} }
...@@ -155,9 +153,8 @@ public: ...@@ -155,9 +153,8 @@ public:
{ {
CheckValid(); CheckValid();
python::object iter; python::object iter;
run_action<>()(_gi, lambda::bind<void>(get_out_edges(), lambda::_1, run_action<>()(_gi, bind<void>(get_out_edges(), _1,
lambda::var(_gi), _v, ref(_gi), _v, ref(iter)))();
lambda::var(iter)))();
return iter; return iter;
} }
...@@ -181,9 +178,8 @@ public: ...@@ -181,9 +178,8 @@ public:
{ {
CheckValid(); CheckValid();
python::object iter; python::object iter;
run_action<>()(_gi, lambda::bind<void>(get_in_edges(), lambda::_1, run_action<>()(_gi, bind<void>(get_in_edges(), _1, ref(_gi),
lambda::var(_gi), _v, _v, ref(iter)))();
lambda::var(iter)))();
return iter; return iter;
} }
...@@ -276,10 +272,8 @@ public: ...@@ -276,10 +272,8 @@ public:
{ {
CheckValid(); CheckValid();
python::object v; python::object v;
run_action<>()(_gi, lambda::bind<void>(get_source(), lambda::_1, run_action<>()(_gi, bind<void>(get_source(), _1, ref(_gi), ref(_e),
lambda::var(_gi), ref(v)))();
lambda::var(_e),
lambda::var(v)))();
return v; return v;
} }
...@@ -298,10 +292,8 @@ public: ...@@ -298,10 +292,8 @@ public:
{ {
CheckValid(); CheckValid();
python::object v; python::object v;
run_action<>()(_gi, lambda::bind<void>(get_target(), lambda::_1, run_action<>()(_gi, bind<void>(get_target(), _1, ref(_gi), ref(_e),