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 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#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_filtering.hh"
#include "graph_properties.hh"
#include <boost/lambda/lambda.hpp>
#include <boost/lambda/bind.hpp>
using namespace std;
using namespace boost;
using namespace boost::lambda;
using namespace graph_tool;
......@@ -64,9 +60,11 @@ size_t GraphInterface::GetNumberOfVertices()
{
size_t n = 0;
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
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;
}
......@@ -75,9 +73,11 @@ size_t GraphInterface::GetNumberOfVertices()
// linear complexity, since num_edges() is O(E) in Boost's adjacency_list
size_t GraphInterface::GetNumberOfEdges()
{
using namespace boost::lambda;
size_t n = 0;
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
n = _nedges;
return n;
......
......@@ -25,8 +25,6 @@
#include "fast_vector_property_map.hh"
#include <boost/dynamic_property_map.hpp>
#include <boost/lambda/lambda.hpp>
#include <boost/lambda/bind.hpp>
#include <boost/variant.hpp>
#include <boost/python/object.hpp>
#include <boost/python/dict.hpp>
......
......@@ -288,8 +288,7 @@ struct graph_type_name
string get_graph_type(GraphInterface& g)
{
string name;
run_action<>()(g, lambda::bind<void>(graph_type_name(), lambda::_1,
lambda::var(name)))();
run_action<>()(g, bind<void>(graph_type_name(), _1, ref(name)))();
return name;
}
......
......@@ -15,8 +15,6 @@
// You should have received a copy of the GNU General Public License
// 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/python/extract.hpp>
......@@ -26,7 +24,6 @@
using namespace std;
using namespace boost;
using namespace boost::lambda;
using namespace graph_tool;
struct graph_copy
......
......@@ -28,7 +28,6 @@
#include <boost/iostreams/filter/bzip2.hpp>
#include <boost/iostreams/device/file_descriptor.hpp>
#include <boost/iostreams/device/file.hpp>
#include <boost/lambda/bind.hpp>
#include <boost/graph/graphml.hpp>
#include <boost/graph/graphviz.hpp>
#include <boost/python/extract.hpp>
......@@ -38,7 +37,6 @@
using namespace std;
using namespace boost;
using namespace boost::lambda;
using namespace graph_tool;
//
......@@ -262,10 +260,9 @@ template <class IndexMap>
python::object find_property_map(dynamic_property_map* map, IndexMap)
{
python::object pmap;
mpl::for_each<value_types>(lambda::bind<void>(get_python_property(),
lambda::_1,
IndexMap(), lambda::var(map),
lambda::var(pmap)));
mpl::for_each<value_types>(bind<void>(get_python_property(),
_1, IndexMap(), ref(map),
ref(pmap)));
return pmap;
}
......@@ -669,25 +666,20 @@ void GraphInterface::WriteToFile(string file, python::object pfile,
typedef tr1::unordered_map<vertex_t, size_t> map_t;
map_t vertex_to_index;
associative_property_map<map_t> index_map(vertex_to_index);
run_action<>()(*this, lambda::bind<void>(generate_index(),
lambda::_1,
index_map))();
run_action<>()(*this, bind<void>(generate_index(),
_1, index_map))();
if (graphviz)
graphviz_insert_index(dp, index_map);
if (GetDirected())
run_action<detail::always_directed>()
(*this, lambda::bind<void>(write_to_file(),
lambda::var(stream),
lambda::_1,
index_map, lambda::var(dp),
graphviz))();
(*this, bind<void>(write_to_file(), ref(stream), _1,
index_map, ref(dp), graphviz))();
else
run_action<detail::never_directed>()
(*this,lambda::bind<void>(write_to_file_fake_undir(),
lambda::var(stream),
lambda::_1, index_map,
lambda::var(dp), graphviz))();
(*this,bind<void>(write_to_file_fake_undir(),
ref(stream), _1, index_map,
ref(dp), graphviz))();
}
else
{
......@@ -696,18 +688,13 @@ void GraphInterface::WriteToFile(string file, python::object pfile,
if (GetDirected())
run_action<detail::always_directed>()
(*this, lambda::bind<void>(write_to_file(),
lambda::var(stream),
lambda::_1, _vertex_index,
lambda::var(dp),
graphviz))();
(*this, bind<void>(write_to_file(), ref(stream), _1,
_vertex_index, ref(dp), graphviz))();
else
run_action<detail::never_directed>()
(*this,lambda::bind<void>(write_to_file_fake_undir(),
lambda::var(stream),
lambda::_1, _vertex_index,
lambda::var(dp),
graphviz))();
(*this,bind<void>(write_to_file_fake_undir(),
ref(stream), _1, _vertex_index,
ref(dp), graphviz))();
}
stream.reset();
}
......
......@@ -20,12 +20,10 @@
#include "graph_selectors.hh"
#include "graph_util.hh"
#include <boost/lambda/bind.hpp>
#include <boost/mpl/for_each.hpp>
using namespace std;
using namespace boost;
using namespace boost::lambda;
using namespace graph_tool;
namespace graph_tool
......@@ -61,8 +59,8 @@ void GraphInterface::ShiftVertexProperty(boost::any prop, size_t index) const
{
bool found = false;
mpl::for_each<writable_vertex_properties>
(lambda::bind<void>(shift_vertex_property(), _1, var(_mg),
prop, index, var(found)));
(bind<void>(shift_vertex_property(), _1, ref(_mg),
prop, index, ref(found)));
if (!found)
throw GraphException("invalid writable property map");
}
......
......@@ -32,7 +32,7 @@
#include <boost/mpl/for_each.hpp>
#include <boost/mpl/transform.hpp>
#include <boost/mpl/find.hpp>
#include <boost/lambda/bind.hpp>
#include <boost/bind.hpp>
#include "graph.hh"
......@@ -185,20 +185,18 @@ public:
{
if (_all_names.empty())
{
using namespace lambda;
mpl::for_each<TypeSequence>
(lambda::bind<void>(get_all_names(), lambda::_1,
var(_type_names), var(_all_names)));
(bind<void>(get_all_names(), _1,
ref(_type_names), ref(_all_names)));
}
}
const string& operator()(const type_info& type) const
{
using namespace lambda;
string* name;
mpl::for_each<TypeSequence>
(lambda::bind<void>(find_name(), lambda::_1, var(type),
var(_all_names), var(name)));
(bind<void>(find_name(), _1, ref(type),
ref(_all_names), ref(name)));
return *name;
}
......@@ -262,8 +260,7 @@ public:
{
ValueConverter* converter = 0;
mpl::for_each<PropertyTypes>
(lambda::bind<void>(choose_converter(), lambda::_1,
lambda::var(pmap), lambda::var(converter)));
(bind<void>(choose_converter(), _1, ref(pmap), ref(converter)));
if (converter == 0)
throw bad_lexical_cast();
else
......
......@@ -20,7 +20,6 @@
#include "graph_python_interface.hh"
#include <boost/python.hpp>
#include <boost/lambda/bind.hpp>
#include <set>
using namespace std;
......@@ -44,9 +43,9 @@ GraphInterface::Vertices() const
{
python::object iter;
run_action<>()(const_cast<GraphInterface&>(*this),
lambda::bind<void>(get_vertex_iterator(), lambda::_1,
lambda::var(const_cast<GraphInterface&>(*this)),
lambda::var(iter)))();
bind<void>(get_vertex_iterator(), _1,
ref(const_cast<GraphInterface&>(*this)),
ref(iter)))();
return iter;
}
......@@ -89,14 +88,14 @@ GraphInterface::Vertex(size_t i) const
python::object v;
if (IsVertexFilterActive())
run_action<>()(const_cast<GraphInterface&>(*this),
lambda::bind<void>(get_vertex_hard(), lambda::_1,
lambda::var(const_cast<GraphInterface&>(*this)),
i, lambda::var(v)))();
bind<void>(get_vertex_hard(), _1,
ref(const_cast<GraphInterface&>(*this)),
i, ref(v)))();
else
run_action<>()(const_cast<GraphInterface&>(*this),
lambda::bind<void>(get_vertex_soft(), lambda::_1,
lambda::var(const_cast<GraphInterface&>(*this)), i,
lambda::var(v)))();
bind<void>(get_vertex_soft(), _1,
ref(const_cast<GraphInterface&>(*this)), i,
ref(v)))();
return v;
}
......@@ -117,9 +116,9 @@ GraphInterface::Edges() const
{
python::object iter;
run_action<>()(const_cast<GraphInterface&>(*this),
lambda::bind<void>(get_edge_iterator(), lambda::_1,
lambda::var(const_cast<GraphInterface&>(*this)),
lambda::var(iter)))();
bind<void>(get_edge_iterator(), _1,
ref(const_cast<GraphInterface&>(*this)),
ref(iter)))();
return iter;
}
......@@ -193,10 +192,10 @@ python::object GraphInterface::AddEdge(const python::object& s,
src.CheckValid();
tgt.CheckValid();
python::object new_e;
run_action<>()(*this, lambda::bind<void>(add_new_edge(), lambda::_1,
lambda::var(*this), src, tgt,
_edge_index,
lambda::var(new_e)))();
run_action<>()(*this, bind<void>(add_new_edge(), _1,
ref(*this), src, tgt,
_edge_index,
ref(new_e)))();
return new_e;
}
......@@ -221,9 +220,9 @@ void GraphInterface::RemoveEdge(const python::object& e)
edge_t de;
bool found = false;
run_action<>()(*this,
lambda::bind<void>(get_edge_descriptor(), lambda::_1,
lambda::var(e), lambda::var(de),
lambda::var(found)))();
bind<void>(get_edge_descriptor(), _1,
ref(e), ref(de),
ref(found)))();
if (!found)
throw ValueException("invalid edge descriptor");
RemoveEdgeIndex(de);
......@@ -283,16 +282,16 @@ python::object GraphInterface::DegreeMap(string deg) const
if (deg == "in")
run_action<>()(const_cast<GraphInterface&>(*this),
lambda::bind<void>(get_degree_map(), lambda::_1,
deg_map, in_degreeS()))();
bind<void>(get_degree_map(), _1,
deg_map, in_degreeS()))();
else if (deg == "out")
run_action<>()(const_cast<GraphInterface&>(*this),
lambda::bind<void>(get_degree_map(), lambda::_1,
deg_map, out_degreeS()))();
bind<void>(get_degree_map(), _1,
deg_map, out_degreeS()))();
else if (deg == "total")
run_action<>()(const_cast<GraphInterface&>(*this),
lambda::bind<void>(get_degree_map(), lambda::_1,
deg_map, total_degreeS()))();
bind<void>(get_degree_map(), _1,
deg_map, total_degreeS()))();
return python::object(PythonPropertyMap<map_t>(deg_map));
}
......@@ -408,9 +407,8 @@ void GraphInterface::ExportPythonInterface() const
set<string> v_iterators;
typedef mpl::transform<graph_tool::detail::all_graph_views,
mpl::quote1<add_pointer> >::type graph_views;
mpl::for_each<graph_views>(lambda::bind<void>(export_python_interface(),
lambda::_1,
lambda::var(v_iterators)));
mpl::for_each<graph_views>(bind<void>(export_python_interface(),
_1,ref(v_iterators)));
export_python_properties(const_cast<GraphInterface&>(*this));
def("new_vertex_property",
&new_property<GraphInterface::vertex_index_map_t>);
......
......@@ -18,7 +18,6 @@
#ifndef PYTHON_INTERFACE_HH
#define PYTHON_INTERFACE_HH
#include <boost/lambda/bind.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/mpl/logical.hpp>
#include <boost/functional/hash.hpp>
......@@ -117,9 +116,9 @@ public:
{
CheckValid();
size_t in_deg;
run_action<>()(_gi,lambda::bind<void>(get_degree<in_degreeS>(),
lambda::_1, _v,
lambda::var(in_deg)))();
run_action<>()(_gi, bind<void>(get_degree<in_degreeS>(),
_1, _v,
ref(in_deg)))();
return in_deg;
}
......@@ -127,9 +126,8 @@ public:
{
CheckValid();
size_t out_deg;
run_action<>()(_gi,lambda::bind<void>(get_degree<out_degreeS>(),
lambda::_1, _v,
lambda::var(out_deg)))();
run_action<>()(_gi, bind<void>(get_degree<out_degreeS>(), _1, _v,
ref(out_deg)))();
return out_deg;
}
......@@ -155,9 +153,8 @@ public:
{
CheckValid();
python::object iter;
run_action<>()(_gi, lambda::bind<void>(get_out_edges(), lambda::_1,
lambda::var(_gi), _v,
lambda::var(iter)))();
run_action<>()(_gi, bind<void>(get_out_edges(), _1,
ref(_gi), _v, ref(iter)))();
return iter;
}
......@@ -181,9 +178,8 @@ public:
{
CheckValid();
python::object iter;
run_action<>()(_gi, lambda::bind<void>(get_in_edges(), lambda::_1,
lambda::var(_gi), _v,
lambda::var(iter)))();
run_action<>()(_gi, bind<void>(get_in_edges(), _1, ref(_gi),
_v, ref(iter)))();
return iter;
}
......@@ -276,10 +272,8 @@ public:
{
CheckValid();
python::object v;
run_action<>()(_gi, lambda::bind<void>(get_source(), lambda::_1,
lambda::var(_gi),
lambda::var(_e),
lambda::var(v)))();
run_action<>()(_gi, bind<void>(get_source(), _1, ref(_gi), ref(_e),
ref(v)))();
return v;
}
......@@ -298,10 +292,8 @@ public:
{
CheckValid();
python::object v;
run_action<>()(_gi, lambda::bind<void>(get_target(), lambda::_1,
lambda::var(_gi),
lambda::var(_e),
lambda::var(v)))();
run_action<>()(_gi, bind<void>(get_target(), _1, ref(_gi), ref(_e),
ref(v)))();
return v;
}
......@@ -498,11 +490,8 @@ python::object new_property(const string& type, IndexMap index_map)
{
python::object prop;
bool found = false;
mpl::for_each<value_types>(lambda::bind<void>(new_property_map(),
lambda::_1, index_map,
lambda::var(type),
lambda::var(prop),
lambda::var(found)));
mpl::for_each<value_types>(bind<void>(new_property_map(), _1, index_map,
ref(type), ref(prop), ref(found)));
if (!found)
throw ValueException("Invalid property type: " + type);
return prop;
......
......@@ -15,14 +15,12 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <boost/lambda/bind.hpp>
#include <boost/variant/get.hpp>
#include "graph.hh"
#include "graph_selectors.hh"
using namespace graph_tool;
using namespace boost;
using namespace boost::lambda;
// retrieves the appropriate degree selector
boost::any graph_tool::degree_selector(GraphInterface::deg_t deg)
......@@ -34,14 +32,15 @@ boost::any graph_tool::degree_selector(GraphInterface::deg_t deg)
if (d != 0)
{
mpl::for_each<selectors>
(bind<void>(get_degree_selector(), _1, *d, var(sel)));
(bind<void>(get_degree_selector(), _1, *d, ref(sel)));
}
else
{
boost::any* d = boost::get<boost::any>(&deg);
bool found = false;
mpl::for_each<vertex_properties>
(bind<void>(get_scalar_selector(), _1, *d, var(sel), var(found)));
(bind<void>(get_scalar_selector(), _1, *d, ref(sel),
ref(found)));
if (!found)
throw ValueException("invalid degree selector");
}
......
......@@ -28,7 +28,6 @@
#include <boost/algorithm/string/trim.hpp>
#include <boost/xpressive/xpressive.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/lambda/bind.hpp>
#include <string>
namespace graph_tool
......
......@@ -23,7 +23,6 @@
using namespace std;
using namespace boost;
using namespace boost::lambda;
using namespace graph_tool;
struct get_denominator_tree
......
......@@ -15,8 +15,6 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <boost/lambda/bind.hpp>
#include "graph.hh"
#include "graph_filtering.hh"
......@@ -24,7 +22,6 @@
using namespace graph_tool;
using namespace boost;
using namespace boost::lambda;
struct check_iso
{
......@@ -63,7 +60,7 @@ bool check_isomorphism(GraphInterface& gi1, GraphInterface& gi2,
run_action<graph_tool::detail::always_directed>()
(gi1, bind<void>(check_iso(),
_1, _2, _3, gi1.GetVertexIndex(),
gi2.GetVertexIndex(), var(result)),
gi2.GetVertexIndex(), ref(result)),
directed_graph_view_pointers(), vertex_props_t())
(gi2.GetGraphView(), iso_map);
}
......@@ -72,7 +69,7 @@ bool check_isomorphism(GraphInterface& gi1, GraphInterface& gi2,
run_action<graph_tool::detail::never_directed>()
(gi1, bind<void>(check_iso(),
_1, _2, _3, gi1.GetVertexIndex(),
gi2.GetVertexIndex(), var(result)),
gi2.GetVertexIndex(), ref(result)),
undirected_graph_view_pointers(), vertex_props_t())
(gi2.GetGraphView(), iso_map);
}
......
......@@ -22,7 +22,6 @@
#include <tr1/unordered_set>
#include <iostream>
#include <iomanip>
#include <boost/lambda/bind.hpp>
#include <boost/graph/graphviz.hpp>
#include <boost/graph/graphml.hpp>
#include <boost/algorithm/string.hpp>
......@@ -33,7 +32,6 @@
using namespace std;
using namespace boost;
using namespace boost::lambda;
using namespace graph_tool;
// retrieves the line graph
......
......@@ -24,7 +24,6 @@
using namespace std;
using namespace boost;
using namespace boost::lambda;
using namespace graph_tool;
struct get_kruskal_min_span_tree
......
......@@ -16,9 +16,6 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <boost/lambda/lambda.hpp>
#include <boost/lambda/bind.hpp>
#include "graph.hh"
#include "graph_filtering.hh"
#include "graph_selectors.hh"
......@@ -26,7 +23,6 @@
using namespace std;
using namespace boost;
using namespace boost::lambda;
using namespace graph_tool;
struct get_reciprocity
......
......@@ -24,7 +24,6 @@
using namespace std;
using namespace boost;
using namespace boost::lambda;
using namespace graph_tool;
struct get_topological_sort
......
......@@ -32,9 +32,8 @@ find_vertex_range(GraphInterface& gi, GraphInterface::deg_t deg,
{
python::list ret;
run_action<>()(gi, lambda::bind<void>(find_vertices(), lambda::_1,
lambda::var(gi), lambda::_2,