Commit fe42f743 authored by Tiago Peixoto's avatar Tiago Peixoto

Port to c++11

parent 0d2a562a
......@@ -53,7 +53,10 @@ AC_ARG_ENABLE([debug], [AS_HELP_STRING([--enable-debug],[compile debug informati
[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"]
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)
{
std::string val;
boost::any oval = pmap.get(v);
mpl::for_each<ValueTypes>(bind<void>(get_string(), ref(oval),
ref(val), _1));
mpl::for_each<ValueTypes>(boost::bind<void>(get_string(), boost::ref(oval),
boost::ref(val), _1));
return val;
}
......
......@@ -144,12 +144,12 @@ namespace boost {
std::vector<invar1_value> invar1_array;
BGL_FORALL_VERTICES_T(v, G1, Graph1)
invar1_array.push_back(invariant1(v));
sort(invar1_array);
std::sort(invar1_array.begin(), invar1_array.end());
std::vector<invar2_value> invar2_array;
BGL_FORALL_VERTICES_T(v, G2, Graph2)
invar2_array.push_back(invariant2(v));
sort(invar2_array);
std::sort(invar2_array.begin(), invar2_array.end());
if (! equal(invar1_array, invar2_array))
return false;
}
......@@ -161,7 +161,8 @@ namespace boost {
std::vector<size_type> multiplicity(max_invariant, 0);
BGL_FORALL_VERTICES_T(v, G1, Graph1)
++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));
......@@ -193,7 +194,7 @@ namespace boost {
for (vertex_iter v = dfs_vertices.begin(); v != dfs_vertices.end(); ++v)
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;
......
......@@ -57,7 +57,6 @@ libgraph_tool_core_la_include_HEADERS = \
random.hh \
str_repr.hh \
shared_map.hh \
tr1_include.hh \
transform_iterator.hh
libgraph_tool_core_la_workarounddir = $(MOD_DIR)/include/boost-workaround/boost/graph/
......
......@@ -36,8 +36,8 @@ void normalize_betweenness(const Graph& g,
{
double vfactor = (n > 2) ? 1.0/((n-1)*(n-2)) : 1.0;
double efactor = (n > 1) ? 1.0/(n*(n-1)) : 1.0;
if (is_convertible<typename graph_traits<Graph>::directed_category,
undirected_tag>::value)
if (std::is_convertible<typename graph_traits<Graph>::directed_category,
undirected_tag>::value)
{
vfactor *= 2;
efactor *= 2;
......@@ -63,6 +63,7 @@ void normalize_betweenness(const Graph& g,
struct get_betweenness
{
typedef void result_type;
template <class Graph, class EdgeBetweenness, class VertexBetweenness>
void operator()(Graph& g,
GraphInterface::vertex_index_map_t index_map,
......@@ -90,6 +91,7 @@ struct get_betweenness
struct get_weighted_betweenness
{
typedef void result_type;
template <class Graph, class EdgeBetweenness, class VertexBetweenness,
class VertexIndexMap>
void operator()(Graph& g, VertexIndexMap vertex_index,
......@@ -137,10 +139,11 @@ void betweenness(GraphInterface& g, boost::any weight,
if (!weight.empty())
{
run_action<>()
(g, bind<void>
(get_weighted_betweenness(), _1, g.GetVertexIndex(),
_2, _3, weight, normalize,
g.GetNumberOfVertices(), g.GetMaxEdgeIndex()),
(g, std::bind<>(get_weighted_betweenness(),
std::placeholders::_1, g.GetVertexIndex(),
std::placeholders::_2,
std::placeholders::_3, weight, normalize,
g.GetNumberOfVertices(), g.GetMaxEdgeIndex()),
edge_floating_properties(),
vertex_floating_properties())
(edge_betweenness, vertex_betweenness);
......@@ -148,8 +151,10 @@ void betweenness(GraphInterface& g, boost::any weight,
else
{
run_action<>()
(g, bind<void>(get_betweenness(), _1, g.GetVertexIndex(), _2,
_3, normalize, g.GetNumberOfVertices()),
(g, std::bind<void>(get_betweenness(), std::placeholders::_1,
g.GetVertexIndex(), std::placeholders::_2,
std::placeholders::_3, normalize,
g.GetNumberOfVertices()),
edge_floating_properties(),
vertex_floating_properties())
(edge_betweenness, vertex_betweenness);
......@@ -171,8 +176,8 @@ double central_point(GraphInterface& g,
{
double c = 0.0;
run_action<graph_tool::detail::never_reversed>()
(g, bind<void>(get_central_point_dominance(), _1,
_2, ref(c)),
(g, std::bind<>(get_central_point_dominance(), std::placeholders::_1,
std::placeholders::_2, std::ref(c)),
vertex_scalar_properties()) (vertex_betweenness);
return c;
}
......
......@@ -22,8 +22,9 @@
#include "graph_closeness.hh"
#include <functional>
using namespace std;
using namespace boost;
using namespace graph_tool;
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())
{
run_action<>()(gi,
bind<void>(get_closeness(), _1,
gi.GetVertexIndex(), no_weightS(),
_2, harmonic, norm),
std::bind(get_closeness(), placeholders::_1,
gi.GetVertexIndex(), no_weightS(),
placeholders::_2, harmonic, norm),
writable_vertex_scalar_properties())(closeness);
}
else
{
run_action<>()(gi,
bind<void>(get_closeness(), _1,
gi.GetVertexIndex(), _2,
_3, harmonic, norm),
std::bind(get_closeness(), placeholders::_1,
gi.GetVertexIndex(), placeholders::_2,
placeholders::_3, harmonic, norm),
edge_scalar_properties(),
writable_vertex_scalar_properties())(weight, closeness);
}
......@@ -50,5 +51,5 @@ void do_get_closeness(GraphInterface& gi, boost::any weight,
void export_closeness()
{
python::def("closeness", &do_get_closeness);
boost::python::def("closeness", &do_get_closeness);
}
......@@ -31,14 +31,13 @@
namespace graph_tool
{
using namespace std;
using namespace boost;
struct no_weightS {};
template <class Map>
struct get_val_type
{
typedef typename property_traits<Map>::value_type type;
typedef typename boost::property_traits<Map>::value_type type;
};
template <>
......@@ -49,16 +48,17 @@ struct get_val_type<no_weightS>
struct get_closeness
{
typedef void result_type;
template <class Graph, class VertexIndex, class WeightMap, class Closeness>
void operator()(const Graph& g, VertexIndex vertex_index, WeightMap weights,
Closeness closeness, bool harmonic, bool norm)
const
{
using namespace boost;
typedef typename graph_traits<Graph>::vertex_descriptor vertex_t;
// 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_djk>::type get_vertex_dists_t;
......@@ -113,7 +113,7 @@ struct get_closeness
}
}
class component_djk_visitor: public dijkstra_visitor<>
class component_djk_visitor: public boost::dijkstra_visitor<>
{
public:
//component_visitor() { }
......@@ -139,6 +139,7 @@ struct get_closeness
DistanceMap dist_map, WeightMap weights,
size_t& comp_size) const
{
using namespace boost;
component_djk_visitor vis(comp_size);
dijkstra_shortest_paths(g, s, vertex_index_map(vertex_index).
weight_map(weights).distance_map(dist_map).visitor(vis));
......@@ -146,7 +147,7 @@ struct get_closeness
};
template <class DistMap>
class component_bfs_visitor: public bfs_visitor<>
class component_bfs_visitor: public boost::bfs_visitor<>
{
public:
//component_visitor() { }
......@@ -179,9 +180,10 @@ struct get_closeness
void operator()(const Graph& g, Vertex s, VertexIndex vertex_index,
DistanceMap dist_map, no_weightS, size_t& comp_size) const
{
using namespace boost;
typedef typename graph_traits<Graph>::vertex_descriptor vertex_t;
typedef tr1::unordered_map<vertex_t,default_color_type,
DescriptorHash<VertexIndex> > cmap_t;
typedef unordered_map<vertex_t,default_color_type,
DescriptorHash<VertexIndex> > cmap_t;
cmap_t cmap(0, DescriptorHash<VertexIndex>(vertex_index));
InitializedPropertyMap<cmap_t>
color_map(cmap, color_traits<default_color_type>::white());
......
......@@ -24,7 +24,6 @@
#include "graph_eigentrust.hh"
using namespace std;
using namespace boost;
using namespace graph_tool;
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;
run_action<>()
(g, bind<void>
(get_eigentrust(),
_1, g.GetVertexIndex(), g.GetEdgeIndex(), _2,
_3, epslon, max_iter, ref(iter)),
(g, bind(get_eigentrust(),
_1, g.GetVertexIndex(), g.GetEdgeIndex(), _2,
_3, epslon, max_iter, ref(iter)),
writable_edge_scalar_properties(),
vertex_floating_properties())(c,t);
return iter;
......
......@@ -25,16 +25,17 @@
namespace graph_tool
{
using namespace std;
using namespace boost;
struct get_eigentrust
{
typedef void result_type;
template <class Graph, class VertexIndex, class EdgeIndex, class TrustMap,
class InferredTrustMap>
void operator()(Graph& g, VertexIndex vertex_index,
EdgeIndex edge_index, TrustMap c, InferredTrustMap t,
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<InferredTrustMap>::value_type t_type;
......
......@@ -17,14 +17,11 @@
#include "graph_filtering.hh"
#include <boost/python.hpp>
#include "graph.hh"
#include "graph_selectors.hh"
#include "graph_eigenvector.hh"
using namespace std;
using namespace boost;
using namespace graph_tool;
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");
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;
if(w.empty())
......@@ -45,14 +42,16 @@ long double eigenvector(GraphInterface& g, boost::any w, boost::any c,
long double eig = 0;
run_action<>()
(g, bind<void>
(get_eigenvector(), _1, g.GetVertexIndex(), _2,
_3, epsilon, max_iter, ref(eig)),
(g, std::bind(get_eigenvector(), placeholders::_1, g.GetVertexIndex(),
placeholders::_2, placeholders::_3, epsilon, max_iter,
std::ref(eig)),
weight_props_t(),
vertex_floating_properties())(w, c);
return eig;
}
#include <boost/python.hpp>
void export_eigenvector()
{
using namespace boost::python;
......
......@@ -22,8 +22,16 @@
#include "graph_filtering.hh"
#include "graph_util.hh"
#ifndef __clang__
#include <ext/numeric>
using __gnu_cxx::power;
#else
template <class Value>
Value power(Value value, int n)
{
return pow(value, n);
}
#endif
namespace graph_tool
{
......
......@@ -60,7 +60,7 @@ long double hits(GraphInterface& g, boost::any w, boost::any x, boost::any y,
" value type");
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;
if(w.empty())
......@@ -68,9 +68,9 @@ long double hits(GraphInterface& g, boost::any w, boost::any x, boost::any y,
long double eig = 0;
run_action<>()
(g, bind<void>
(get_hits_dispatch(), _1, g.GetVertexIndex(), _2,
_3, y, epsilon, max_iter, ref(eig)),
(g, std::bind(get_hits_dispatch(), placeholders::_1, g.GetVertexIndex(),
placeholders::_2, placeholders::_3, y, epsilon, max_iter,
std::ref(eig)),
weight_props_t(),
vertex_floating_properties())(w, x);
return eig;
......
......@@ -22,8 +22,16 @@
#include "graph_filtering.hh"
#include "graph_util.hh"
#ifndef __clang__
#include <ext/numeric>
using __gnu_cxx::power;
#else
template <class Value>
Value power(Value value, int n)
{
return pow(value, n);
}
#endif
namespace graph_tool
{
......
......@@ -40,22 +40,22 @@ void katz(GraphInterface& g, boost::any w, boost::any c, boost::any beta,
" value type");
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;
if(w.empty())
w = weight_map_t(1.);
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;
if(beta.empty())
beta = beta_map_t(1.);
run_action<>()(g, bind<void>
(get_katz(), _1, g.GetVertexIndex(), _2,
_3, _4, alpha, epsilon, max_iter),
run_action<>()(g, std::bind(get_katz(), placeholders::_1, g.GetVertexIndex(),
placeholders::_2, placeholders::_3,
placeholders::_4, alpha, epsilon, max_iter),
weight_props_t(),
vertex_floating_properties(),
beta_props_t())(w, c, beta);
......
......@@ -22,8 +22,16 @@
#include "graph_filtering.hh"
#include "graph_util.hh"
#ifndef __clang__
#include <ext/numeric>
using __gnu_cxx::power;
#else
template <class Value>
Value power(Value value, int n)
{
return pow(value, n);
}
#endif
namespace graph_tool
{
......
......@@ -38,14 +38,14 @@ size_t pagerank(GraphInterface& g, boost::any rank, boost::any pers,
throw ValueException("personalization vertex property must have a scalar value type");
typedef ConstantPropertyMap<double, GraphInterface::vertex_t> pers_map_t;
typedef mpl::push_back<vertex_scalar_properties, pers_map_t>::type
typedef boost::mpl::push_back<vertex_scalar_properties, pers_map_t>::type
pers_props_t;
if(pers.empty())
pers = pers_map_t(1.0 / g.GetNumberOfVertices());
typedef ConstantPropertyMap<double, GraphInterface::edge_t> weight_map_t;
typedef mpl::push_back<edge_scalar_properties, weight_map_t>::type
typedef boost::mpl::push_back<edge_scalar_properties, weight_map_t>::type
weight_props_t;
if (!weight.empty() && !belongs<edge_scalar_properties>()(weight))
......@@ -56,9 +56,10 @@ size_t pagerank(GraphInterface& g, boost::any rank, boost::any pers,
size_t iter;
run_action<>()
(g, bind<void>(get_pagerank(),
_1, g.GetVertexIndex(), _2, _3, _4, d,
epsilon, max_iter, ref(iter)),
(g, std::bind(get_pagerank(),
placeholders::_1, g.GetVertexIndex(), placeholders::_2,
placeholders::_3, placeholders::_4, d,
epsilon, max_iter, std::ref(iter)),
vertex_floating_properties(),
pers_props_t(), weight_props_t())(rank, pers, weight);
return iter;
......
......@@ -31,15 +31,16 @@ using namespace std;
using namespace boost;
using namespace graph_tool;
python::tuple global_clustering(GraphInterface& g)
boost::python::tuple global_clustering(GraphInterface& g)
{
double c, c_err;
bool directed = g.GetDirected();
g.SetDirected(false);
run_action<graph_tool::detail::never_directed>()
(g, bind<void>(get_global_clustering(), _1, ref(c), ref(c_err)))();
(g, std::bind(get_global_clustering(), std::placeholders::_1,
std::ref(c), std::ref(c_err)))();
g.SetDirected(directed);
return python::make_tuple(c, c_err);
return boost::python::make_tuple(c, c_err);
}
void local_clustering(GraphInterface& g, boost::any prop)
......@@ -47,17 +48,19 @@ void local_clustering(GraphInterface& g, boost::any prop)
bool directed = g.GetDirected();
g.SetDirected(false);
run_action<graph_tool::detail::never_directed>()
(g, bind<void>(set_clustering_to_property(), _1, _2),
(g, std::bind(set_clustering_to_property(),
std::placeholders::_1,
std::placeholders::_2),
writable_vertex_scalar_properties())(prop);
g.SetDirected(directed);
}
using namespace boost::python;
void extended_clustering(GraphInterface& g, python::list props);
void get_motifs(GraphInterface& g, size_t k, python::list subgraph_list,
python::list hist, python::list pvmaps, bool collect_vmaps,
python::list p, bool comp_iso, bool fill_list, rng_t& rng);
void extended_clustering(GraphInterface& g, boost::python::list props);
void get_motifs(GraphInterface& g, size_t k, boost::python::list subgraph_list,
boost::python::list hist, boost::python::list pvmaps, bool collect_vmaps,
boost::python::list p, bool comp_iso, bool fill_list, rng_t& rng);
BOOST_PYTHON_MODULE(libgraph_tool_clustering)
{
......
......@@ -20,16 +20,23 @@
#include "config.h"
#include "tr1_include.hh"
#include TR1_HEADER(unordered_set)
#include <unordered_set>
#include <boost/mpl/if.hpp>
#ifdef HAVE_SPARSEHASH
#include <dense_hash_set>
#endif
#ifndef __clang__
#include <ext/numeric>
using __gnu_cxx::power;
#else
template <class Value>
Value power(Value value, int n)
{
return pow(value, n);
}
#endif
namespace graph_tool
{
......@@ -37,6 +44,8 @@ using namespace boost;
#ifdef HAVE_SPARSEHASH
using google::dense_hash_set;
#else
using std::unordered_set;
#endif
// calculates the number of triangles to which v belongs
......@@ -162,10 +171,10 @@ struct set_clustering_to_property
struct get_undirected_graph
{
typedef typename mpl::if_
< is_convertible<typename graph_traits<Graph>::directed_category,
directed_tag>,
const UndirectedAdaptor<Graph>,
const Graph& >::type type;
<std::is_convertible<typename graph_traits<Graph>::directed_category,
directed_tag>,
const UndirectedAdaptor<Graph>,
const Graph& >::type type;
};
};
......
......@@ -35,9 +35,9 @@ struct prop_vector
boost::any operator()(const vector<boost::any>& props, size_t size) const
{
boost::any prop_vec;
mpl::for_each<PropertySequence>
(bind<void>(get_prop_vector(), _1, ref(props), ref(prop_vec),