Commit fe42f743 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Port to c++11

parent 0d2a562a
...@@ -53,7 +53,10 @@ AC_ARG_ENABLE([debug], [AS_HELP_STRING([--enable-debug],[compile debug informati ...@@ -53,7 +53,10 @@ AC_ARG_ENABLE([debug], [AS_HELP_STRING([--enable-debug],[compile debug informati
[AC_MSG_RESULT(no)] [AC_MSG_RESULT(no)]
) )
dnl set template depth and hidden visibility dnl enable c++11
[CXXFLAGS="${CXXFLAGS} -std=gnu++11"]
dnl set template depth
[CXXFLAGS="${CXXFLAGS} -ftemplate-depth-150"] [CXXFLAGS="${CXXFLAGS} -ftemplate-depth-150"]
dnl disable deprecation warning, to silence some harmless BGL-related warnings dnl disable deprecation warning, to silence some harmless BGL-related warnings
......
...@@ -328,8 +328,8 @@ std::string print_value(dynamic_property_map& pmap, Descriptor v) ...@@ -328,8 +328,8 @@ std::string print_value(dynamic_property_map& pmap, Descriptor v)
{ {
std::string val; std::string val;
boost::any oval = pmap.get(v); boost::any oval = pmap.get(v);
mpl::for_each<ValueTypes>(bind<void>(get_string(), ref(oval), mpl::for_each<ValueTypes>(boost::bind<void>(get_string(), boost::ref(oval),
ref(val), _1)); boost::ref(val), _1));
return val; return val;
} }
......
...@@ -144,12 +144,12 @@ namespace boost { ...@@ -144,12 +144,12 @@ namespace boost {
std::vector<invar1_value> invar1_array; std::vector<invar1_value> invar1_array;
BGL_FORALL_VERTICES_T(v, G1, Graph1) BGL_FORALL_VERTICES_T(v, G1, Graph1)
invar1_array.push_back(invariant1(v)); invar1_array.push_back(invariant1(v));
sort(invar1_array); std::sort(invar1_array.begin(), invar1_array.end());
std::vector<invar2_value> invar2_array; std::vector<invar2_value> invar2_array;
BGL_FORALL_VERTICES_T(v, G2, Graph2) BGL_FORALL_VERTICES_T(v, G2, Graph2)
invar2_array.push_back(invariant2(v)); invar2_array.push_back(invariant2(v));
sort(invar2_array); std::sort(invar2_array.begin(), invar2_array.end());
if (! equal(invar1_array, invar2_array)) if (! equal(invar1_array, invar2_array))
return false; return false;
} }
...@@ -161,7 +161,8 @@ namespace boost { ...@@ -161,7 +161,8 @@ namespace boost {
std::vector<size_type> multiplicity(max_invariant, 0); std::vector<size_type> multiplicity(max_invariant, 0);
BGL_FORALL_VERTICES_T(v, G1, Graph1) BGL_FORALL_VERTICES_T(v, G1, Graph1)
++multiplicity.at(invariant1(v)); ++multiplicity.at(invariant1(v));
sort(V_mult, compare_multiplicity(invariant1, &multiplicity[0])); std::sort(V_mult.begin(), V_mult.end(),
compare_multiplicity(invariant1, &multiplicity[0]));
} }
std::vector<default_color_type> color_vec(num_vertices(G1)); std::vector<default_color_type> color_vec(num_vertices(G1));
...@@ -193,7 +194,7 @@ namespace boost { ...@@ -193,7 +194,7 @@ namespace boost {
for (vertex_iter v = dfs_vertices.begin(); v != dfs_vertices.end(); ++v) for (vertex_iter v = dfs_vertices.begin(); v != dfs_vertices.end(); ++v)
dfs_num[*v] = n++; dfs_num[*v] = n++;
sort(ordered_edges, edge_cmp(G1, dfs_num)); std::sort(ordered_edges.begin(), ordered_edges.end(), edge_cmp(G1, dfs_num));
int dfs_num_k = -1; int dfs_num_k = -1;
......
...@@ -57,7 +57,6 @@ libgraph_tool_core_la_include_HEADERS = \ ...@@ -57,7 +57,6 @@ libgraph_tool_core_la_include_HEADERS = \
random.hh \ random.hh \
str_repr.hh \ str_repr.hh \
shared_map.hh \ shared_map.hh \
tr1_include.hh \
transform_iterator.hh transform_iterator.hh
libgraph_tool_core_la_workarounddir = $(MOD_DIR)/include/boost-workaround/boost/graph/ libgraph_tool_core_la_workarounddir = $(MOD_DIR)/include/boost-workaround/boost/graph/
......
...@@ -36,8 +36,8 @@ void normalize_betweenness(const Graph& g, ...@@ -36,8 +36,8 @@ void normalize_betweenness(const Graph& g,
{ {
double vfactor = (n > 2) ? 1.0/((n-1)*(n-2)) : 1.0; double vfactor = (n > 2) ? 1.0/((n-1)*(n-2)) : 1.0;
double efactor = (n > 1) ? 1.0/(n*(n-1)) : 1.0; double efactor = (n > 1) ? 1.0/(n*(n-1)) : 1.0;
if (is_convertible<typename graph_traits<Graph>::directed_category, if (std::is_convertible<typename graph_traits<Graph>::directed_category,
undirected_tag>::value) undirected_tag>::value)
{ {
vfactor *= 2; vfactor *= 2;
efactor *= 2; efactor *= 2;
...@@ -63,6 +63,7 @@ void normalize_betweenness(const Graph& g, ...@@ -63,6 +63,7 @@ void normalize_betweenness(const Graph& g,
struct get_betweenness struct get_betweenness
{ {
typedef void result_type;
template <class Graph, class EdgeBetweenness, class VertexBetweenness> template <class Graph, class EdgeBetweenness, class VertexBetweenness>
void operator()(Graph& g, void operator()(Graph& g,
GraphInterface::vertex_index_map_t index_map, GraphInterface::vertex_index_map_t index_map,
...@@ -90,6 +91,7 @@ struct get_betweenness ...@@ -90,6 +91,7 @@ struct get_betweenness
struct get_weighted_betweenness struct get_weighted_betweenness
{ {
typedef void result_type;
template <class Graph, class EdgeBetweenness, class VertexBetweenness, template <class Graph, class EdgeBetweenness, class VertexBetweenness,
class VertexIndexMap> class VertexIndexMap>
void operator()(Graph& g, VertexIndexMap vertex_index, void operator()(Graph& g, VertexIndexMap vertex_index,
...@@ -137,10 +139,11 @@ void betweenness(GraphInterface& g, boost::any weight, ...@@ -137,10 +139,11 @@ void betweenness(GraphInterface& g, boost::any weight,
if (!weight.empty()) if (!weight.empty())
{ {
run_action<>() run_action<>()
(g, bind<void> (g, std::bind<>(get_weighted_betweenness(),
(get_weighted_betweenness(), _1, g.GetVertexIndex(), std::placeholders::_1, g.GetVertexIndex(),
_2, _3, weight, normalize, std::placeholders::_2,
g.GetNumberOfVertices(), g.GetMaxEdgeIndex()), std::placeholders::_3, weight, normalize,
g.GetNumberOfVertices(), g.GetMaxEdgeIndex()),
edge_floating_properties(), edge_floating_properties(),
vertex_floating_properties()) vertex_floating_properties())
(edge_betweenness, vertex_betweenness); (edge_betweenness, vertex_betweenness);
...@@ -148,8 +151,10 @@ void betweenness(GraphInterface& g, boost::any weight, ...@@ -148,8 +151,10 @@ void betweenness(GraphInterface& g, boost::any weight,
else else
{ {
run_action<>() run_action<>()
(g, bind<void>(get_betweenness(), _1, g.GetVertexIndex(), _2, (g, std::bind<void>(get_betweenness(), std::placeholders::_1,
_3, normalize, g.GetNumberOfVertices()), g.GetVertexIndex(), std::placeholders::_2,
std::placeholders::_3, normalize,
g.GetNumberOfVertices()),
edge_floating_properties(), edge_floating_properties(),
vertex_floating_properties()) vertex_floating_properties())
(edge_betweenness, vertex_betweenness); (edge_betweenness, vertex_betweenness);
...@@ -171,8 +176,8 @@ double central_point(GraphInterface& g, ...@@ -171,8 +176,8 @@ double central_point(GraphInterface& g,
{ {
double c = 0.0; double c = 0.0;
run_action<graph_tool::detail::never_reversed>() run_action<graph_tool::detail::never_reversed>()
(g, bind<void>(get_central_point_dominance(), _1, (g, std::bind<>(get_central_point_dominance(), std::placeholders::_1,
_2, ref(c)), std::placeholders::_2, std::ref(c)),
vertex_scalar_properties()) (vertex_betweenness); vertex_scalar_properties()) (vertex_betweenness);
return c; return c;
} }
......
...@@ -22,8 +22,9 @@ ...@@ -22,8 +22,9 @@
#include "graph_closeness.hh" #include "graph_closeness.hh"
#include <functional>
using namespace std; using namespace std;
using namespace boost;
using namespace graph_tool; using namespace graph_tool;
void do_get_closeness(GraphInterface& gi, boost::any weight, void do_get_closeness(GraphInterface& gi, boost::any weight,
...@@ -32,17 +33,17 @@ void do_get_closeness(GraphInterface& gi, boost::any weight, ...@@ -32,17 +33,17 @@ void do_get_closeness(GraphInterface& gi, boost::any weight,
if (weight.empty()) if (weight.empty())
{ {
run_action<>()(gi, run_action<>()(gi,
bind<void>(get_closeness(), _1, std::bind(get_closeness(), placeholders::_1,
gi.GetVertexIndex(), no_weightS(), gi.GetVertexIndex(), no_weightS(),
_2, harmonic, norm), placeholders::_2, harmonic, norm),
writable_vertex_scalar_properties())(closeness); writable_vertex_scalar_properties())(closeness);
} }
else else
{ {
run_action<>()(gi, run_action<>()(gi,
bind<void>(get_closeness(), _1, std::bind(get_closeness(), placeholders::_1,
gi.GetVertexIndex(), _2, gi.GetVertexIndex(), placeholders::_2,
_3, harmonic, norm), placeholders::_3, harmonic, norm),
edge_scalar_properties(), edge_scalar_properties(),
writable_vertex_scalar_properties())(weight, closeness); writable_vertex_scalar_properties())(weight, closeness);
} }
...@@ -50,5 +51,5 @@ void do_get_closeness(GraphInterface& gi, boost::any weight, ...@@ -50,5 +51,5 @@ void do_get_closeness(GraphInterface& gi, boost::any weight,
void export_closeness() void export_closeness()
{ {
python::def("closeness", &do_get_closeness); boost::python::def("closeness", &do_get_closeness);
} }
...@@ -31,14 +31,13 @@ ...@@ -31,14 +31,13 @@
namespace graph_tool namespace graph_tool
{ {
using namespace std; using namespace std;
using namespace boost;
struct no_weightS {}; struct no_weightS {};
template <class Map> template <class Map>
struct get_val_type struct get_val_type
{ {
typedef typename property_traits<Map>::value_type type; typedef typename boost::property_traits<Map>::value_type type;
}; };
template <> template <>
...@@ -49,16 +48,17 @@ struct get_val_type<no_weightS> ...@@ -49,16 +48,17 @@ struct get_val_type<no_weightS>
struct get_closeness struct get_closeness
{ {
typedef void result_type;
template <class Graph, class VertexIndex, class WeightMap, class Closeness> template <class Graph, class VertexIndex, class WeightMap, class Closeness>
void operator()(const Graph& g, VertexIndex vertex_index, WeightMap weights, void operator()(const Graph& g, VertexIndex vertex_index, WeightMap weights,
Closeness closeness, bool harmonic, bool norm) Closeness closeness, bool harmonic, bool norm)
const const
{ {
using namespace boost;
typedef typename graph_traits<Graph>::vertex_descriptor vertex_t; typedef typename graph_traits<Graph>::vertex_descriptor vertex_t;
// select get_vertex_dists based on the existence of weights // select get_vertex_dists based on the existence of weights
typedef typename mpl::if_<is_same<WeightMap, no_weightS>, typedef typename mpl::if_<std::is_same<WeightMap, no_weightS>,
get_dists_bfs, get_dists_bfs,
get_dists_djk>::type get_vertex_dists_t; get_dists_djk>::type get_vertex_dists_t;
...@@ -113,7 +113,7 @@ struct get_closeness ...@@ -113,7 +113,7 @@ struct get_closeness
} }
} }
class component_djk_visitor: public dijkstra_visitor<> class component_djk_visitor: public boost::dijkstra_visitor<>
{ {
public: public:
//component_visitor() { } //component_visitor() { }
...@@ -139,6 +139,7 @@ struct get_closeness ...@@ -139,6 +139,7 @@ struct get_closeness
DistanceMap dist_map, WeightMap weights, DistanceMap dist_map, WeightMap weights,
size_t& comp_size) const size_t& comp_size) const
{ {
using namespace boost;
component_djk_visitor vis(comp_size); component_djk_visitor vis(comp_size);
dijkstra_shortest_paths(g, s, vertex_index_map(vertex_index). dijkstra_shortest_paths(g, s, vertex_index_map(vertex_index).
weight_map(weights).distance_map(dist_map).visitor(vis)); weight_map(weights).distance_map(dist_map).visitor(vis));
...@@ -146,7 +147,7 @@ struct get_closeness ...@@ -146,7 +147,7 @@ struct get_closeness
}; };
template <class DistMap> template <class DistMap>
class component_bfs_visitor: public bfs_visitor<> class component_bfs_visitor: public boost::bfs_visitor<>
{ {
public: public:
//component_visitor() { } //component_visitor() { }
...@@ -179,9 +180,10 @@ struct get_closeness ...@@ -179,9 +180,10 @@ struct get_closeness
void operator()(const Graph& g, Vertex s, VertexIndex vertex_index, void operator()(const Graph& g, Vertex s, VertexIndex vertex_index,
DistanceMap dist_map, no_weightS, size_t& comp_size) const DistanceMap dist_map, no_weightS, size_t& comp_size) const
{ {
using namespace boost;
typedef typename graph_traits<Graph>::vertex_descriptor vertex_t; typedef typename graph_traits<Graph>::vertex_descriptor vertex_t;
typedef tr1::unordered_map<vertex_t,default_color_type, typedef unordered_map<vertex_t,default_color_type,
DescriptorHash<VertexIndex> > cmap_t; DescriptorHash<VertexIndex> > cmap_t;
cmap_t cmap(0, DescriptorHash<VertexIndex>(vertex_index)); cmap_t cmap(0, DescriptorHash<VertexIndex>(vertex_index));
InitializedPropertyMap<cmap_t> InitializedPropertyMap<cmap_t>
color_map(cmap, color_traits<default_color_type>::white()); color_map(cmap, color_traits<default_color_type>::white());
......
...@@ -24,7 +24,6 @@ ...@@ -24,7 +24,6 @@
#include "graph_eigentrust.hh" #include "graph_eigentrust.hh"
using namespace std; using namespace std;
using namespace boost;
using namespace graph_tool; using namespace graph_tool;
size_t eigentrust(GraphInterface& g, boost::any c, boost::any t, size_t eigentrust(GraphInterface& g, boost::any c, boost::any t,
...@@ -38,10 +37,9 @@ size_t eigentrust(GraphInterface& g, boost::any c, boost::any t, ...@@ -38,10 +37,9 @@ size_t eigentrust(GraphInterface& g, boost::any c, boost::any t,
size_t iter = 0; size_t iter = 0;
run_action<>() run_action<>()
(g, bind<void> (g, bind(get_eigentrust(),
(get_eigentrust(), _1, g.GetVertexIndex(), g.GetEdgeIndex(), _2,
_1, g.GetVertexIndex(), g.GetEdgeIndex(), _2, _3, epslon, max_iter, ref(iter)),
_3, epslon, max_iter, ref(iter)),
writable_edge_scalar_properties(), writable_edge_scalar_properties(),
vertex_floating_properties())(c,t); vertex_floating_properties())(c,t);
return iter; return iter;
......
...@@ -25,16 +25,17 @@ ...@@ -25,16 +25,17 @@
namespace graph_tool namespace graph_tool
{ {
using namespace std; using namespace std;
using namespace boost;
struct get_eigentrust struct get_eigentrust
{ {
typedef void result_type;
template <class Graph, class VertexIndex, class EdgeIndex, class TrustMap, template <class Graph, class VertexIndex, class EdgeIndex, class TrustMap,
class InferredTrustMap> class InferredTrustMap>
void operator()(Graph& g, VertexIndex vertex_index, void operator()(Graph& g, VertexIndex vertex_index,
EdgeIndex edge_index, TrustMap c, InferredTrustMap t, EdgeIndex edge_index, TrustMap c, InferredTrustMap t,
double epslon, size_t max_iter, size_t& iter) const double epslon, size_t max_iter, size_t& iter) const
{ {
using namespace boost;
typedef typename property_traits<TrustMap>::value_type c_type; typedef typename property_traits<TrustMap>::value_type c_type;
typedef typename property_traits<InferredTrustMap>::value_type t_type; typedef typename property_traits<InferredTrustMap>::value_type t_type;
......
...@@ -17,14 +17,11 @@ ...@@ -17,14 +17,11 @@
#include "graph_filtering.hh" #include "graph_filtering.hh"
#include <boost/python.hpp>
#include "graph.hh" #include "graph.hh"
#include "graph_selectors.hh" #include "graph_selectors.hh"
#include "graph_eigenvector.hh" #include "graph_eigenvector.hh"
using namespace std; using namespace std;
using namespace boost;
using namespace graph_tool; using namespace graph_tool;
long double eigenvector(GraphInterface& g, boost::any w, boost::any c, long double eigenvector(GraphInterface& g, boost::any w, boost::any c,
...@@ -37,7 +34,7 @@ long double eigenvector(GraphInterface& g, boost::any w, boost::any c, ...@@ -37,7 +34,7 @@ long double eigenvector(GraphInterface& g, boost::any w, boost::any c,
" value type"); " value type");
typedef ConstantPropertyMap<int, GraphInterface::edge_t> weight_map_t; typedef ConstantPropertyMap<int, GraphInterface::edge_t> weight_map_t;
typedef mpl::push_back<writable_edge_scalar_properties, weight_map_t>::type typedef boost::mpl::push_back<writable_edge_scalar_properties, weight_map_t>::type
weight_props_t; weight_props_t;
if(w.empty()) if(w.empty())
...@@ -45,14 +42,16 @@ long double eigenvector(GraphInterface& g, boost::any w, boost::any c, ...@@ -45,14 +42,16 @@ long double eigenvector(GraphInterface& g, boost::any w, boost::any c,
long double eig = 0; long double eig = 0;
run_action<>() run_action<>()
(g, bind<void> (g, std::bind(get_eigenvector(), placeholders::_1, g.GetVertexIndex(),
(get_eigenvector(), _1, g.GetVertexIndex(), _2, placeholders::_2, placeholders::_3, epsilon, max_iter,
_3, epsilon, max_iter, ref(eig)), std::ref(eig)),
weight_props_t(), weight_props_t(),
vertex_floating_properties())(w, c); vertex_floating_properties())(w, c);
return eig; return eig;
} }
#include <boost/python.hpp>
void export_eigenvector() void export_eigenvector()
{ {
using namespace boost::python; using namespace boost::python;
......
...@@ -22,8 +22,16 @@ ...@@ -22,8 +22,16 @@
#include "graph_filtering.hh" #include "graph_filtering.hh"
#include "graph_util.hh" #include "graph_util.hh"
#ifndef __clang__
#include <ext/numeric> #include <ext/numeric>
using __gnu_cxx::power; using __gnu_cxx::power;
#else
template <class Value>
Value power(Value value, int n)
{
return pow(value, n);
}
#endif
namespace graph_tool namespace graph_tool
{ {
......
...@@ -60,7 +60,7 @@ long double hits(GraphInterface& g, boost::any w, boost::any x, boost::any y, ...@@ -60,7 +60,7 @@ long double hits(GraphInterface& g, boost::any w, boost::any x, boost::any y,
" value type"); " value type");
typedef ConstantPropertyMap<int, GraphInterface::edge_t> weight_map_t; typedef ConstantPropertyMap<int, GraphInterface::edge_t> weight_map_t;
typedef mpl::push_back<writable_edge_scalar_properties, weight_map_t>::type typedef boost::mpl::push_back<writable_edge_scalar_properties, weight_map_t>::type
weight_props_t; weight_props_t;
if(w.empty()) if(w.empty())
...@@ -68,9 +68,9 @@ long double hits(GraphInterface& g, boost::any w, boost::any x, boost::any y, ...@@ -68,9 +68,9 @@ long double hits(GraphInterface& g, boost::any w, boost::any x, boost::any y,
long double eig = 0; long double eig = 0;
run_action<>() run_action<>()
(g, bind<void> (g, std::bind(get_hits_dispatch(), placeholders::_1, g.GetVertexIndex(),
(get_hits_dispatch(), _1, g.GetVertexIndex(), _2, placeholders::_2, placeholders::_3, y, epsilon, max_iter,
_3, y, epsilon, max_iter, ref(eig)), std::ref(eig)),
weight_props_t(), weight_props_t(),
vertex_floating_properties())(w, x); vertex_floating_properties())(w, x);
return eig; return eig;
......
...@@ -22,8 +22,16 @@ ...@@ -22,8 +22,16 @@
#include "graph_filtering.hh" #include "graph_filtering.hh"
#include "graph_util.hh" #include "graph_util.hh"
#ifndef __clang__
#include <ext/numeric> #include <ext/numeric>
using __gnu_cxx::power; using __gnu_cxx::power;
#else
template <class Value>
Value power(Value value, int n)
{
return pow(value, n);
}
#endif
namespace graph_tool namespace graph_tool
{ {
......
...@@ -40,22 +40,22 @@ void katz(GraphInterface& g, boost::any w, boost::any c, boost::any beta, ...@@ -40,22 +40,22 @@ void katz(GraphInterface& g, boost::any w, boost::any c, boost::any beta,
" value type"); " value type");
typedef ConstantPropertyMap<double, GraphInterface::edge_t> weight_map_t; typedef ConstantPropertyMap<double, GraphInterface::edge_t> weight_map_t;
typedef mpl::push_back<writable_edge_scalar_properties, weight_map_t>::type typedef boost::mpl::push_back<writable_edge_scalar_properties, weight_map_t>::type
weight_props_t; weight_props_t;
if(w.empty()) if(w.empty())
w = weight_map_t(1.); w = weight_map_t(1.);
typedef ConstantPropertyMap<double, GraphInterface::vertex_t> beta_map_t; typedef ConstantPropertyMap<double, GraphInterface::vertex_t> beta_map_t;
typedef mpl::push_back<vertex_floating_properties, beta_map_t>::type typedef boost::mpl::push_back<vertex_floating_properties, beta_map_t>::type
beta_props_t; beta_props_t;