Commit 94a72423 authored by Tiago Peixoto's avatar Tiago Peixoto
Browse files

Purge typeof() in favor or decltype() or auto

parent 69885931
......@@ -33,7 +33,7 @@ using namespace boost;
template <class Value>
void insert_sorted(std::vector<Value>& v, const Value& val)
{
typeof(v.begin()) iter = lower_bound(v.begin(), v.end(), val);
auto iter = lower_bound(v.begin(), v.end(), val);
if (iter != v.end() && *iter == val)
return; // no repetitions
v.insert(iter, val);
......@@ -42,7 +42,7 @@ void insert_sorted(std::vector<Value>& v, const Value& val)
template <class Value>
bool has_val(std::vector<Value>& v, const Value& val)
{
typeof(v.begin()) iter = lower_bound(v.begin(), v.end(), val);
auto iter = lower_bound(v.begin(), v.end(), val);
if (iter == v.end())
return false;
return *iter == val;
......@@ -211,8 +211,7 @@ void make_subgraph
for (tie(e, e_end) = out_edges(ov, g); e != e_end; ++e)
{
ot = target(*e, g);
typeof(vlist.begin()) viter =
lower_bound(vlist.begin(), vlist.end(), ot);
auto viter = lower_bound(vlist.begin(), vlist.end(), ot);
size_t ot_index = viter - vlist.begin();
if (viter != vlist.end() && vlist[ot_index] == ot &&
(is_directed::apply<Graph>::type::value || ot < ov))
......@@ -378,7 +377,7 @@ struct get_all_motifs
make_subgraph(subgraphs[j], g, sub);
get_sig(sub, sig);
typeof(sub_list.begin()) iter = sub_list.find(sig);
auto iter = sub_list.find(sig);
if(iter == sub_list.end())
{
if (!fill_list)
......@@ -388,7 +387,7 @@ struct get_all_motifs
bool found = false;
size_t pos;
typeof(sub_list.begin()) sl = sub_list.find(sig);
auto sl = sub_list.find(sig);
if (sl != sub_list.end())
{
for (size_t l = 0; l < sl->second.size(); ++l)
......
......@@ -160,8 +160,7 @@ struct get_communities
}
swap(s, temp_s);
for (typeof(updates.begin()) iter = updates.begin();
iter != updates.end(); ++iter)
for (auto iter = updates.begin(); iter != updates.end(); ++iter)
Nnnks.Update(std::get<0>(*iter), std::get<1>(*iter),
std::get<2>(*iter));
......@@ -171,8 +170,7 @@ struct get_communities
cout << "\b";
out_str.str("");
size_t ns = 0;
for (typeof(Ns.begin()) iter = Ns.begin(); iter != Ns.end();
++iter)
for (auto iter = Ns.begin(); iter != Ns.end(); ++iter)
if (iter->second > 0)
ns++;
out_str << setw(lexical_cast<string>(n_iter).size())
......@@ -188,7 +186,7 @@ struct get_communities
try
{
size_t ns = 0;
for (typeof(Ns.begin()) iter = Ns.begin(); iter != Ns.end();
for (decltype(Ns.begin()) iter = Ns.begin(); iter != Ns.end();
++iter)
if (iter->second > 0)
ns++;
......@@ -259,7 +257,7 @@ public:
double operator()(size_t, size_t s) const
{
size_t ns = 0;
typeof(_Ns.begin()) iter = _Ns.find(s);
auto iter = _Ns.find(s);
if (iter != _Ns.end())
ns = iter->second;
return _p*ns;
......@@ -296,7 +294,7 @@ public:
double operator()(size_t k, size_t s) const
{
size_t ks = 0;
typeof(_Ks.begin()) iter = _Ks.find(s);
auto iter = _Ks.find(s);
if (iter != _Ks.end())
ks = iter->second;
return k*ks/double(_K);
......@@ -343,27 +341,25 @@ public:
}
}
for (typeof(_Pkk.begin()) iter1 = _Pkk.begin(); iter1 != _Pkk.end();
for (auto iter1 = _Pkk.begin(); iter1 != _Pkk.end();
++iter1)
{
double sum = 0;
for (typeof(iter1->second.begin()) iter2 = iter1->second.begin();
for (auto iter2 = iter1->second.begin();
iter2 != iter1->second.end(); ++iter2)
sum += iter2->second;
for (typeof(iter1->second.begin()) iter2 = iter1->second.begin();
for (auto iter2 = iter1->second.begin();
iter2 != iter1->second.end(); ++iter2)
iter2->second /= sum;
}
for (typeof(_Nk.begin()) k_iter = _Nk.begin(); k_iter != _Nk.end();
for (auto k_iter = _Nk.begin(); k_iter != _Nk.end();
++k_iter)
{
size_t k1 = k_iter->first;
_degs.push_back(k1);
for (typeof(spins.begin()) s_iter = spins.begin();
s_iter != spins.end(); ++s_iter)
for (typeof(_Nk.begin()) k_iter2 = _Nk.begin();
k_iter2 != _Nk.end(); ++k_iter2)
for (auto s_iter = spins.begin(); s_iter != spins.end(); ++s_iter)
for (auto k_iter2 = _Nk.begin(); k_iter2 != _Nk.end(); ++k_iter2)
{
size_t k2 = k_iter2->first;
if (_Nks[k2].find(*s_iter) != _Nks[k2].end())
......@@ -425,7 +421,7 @@ public:
double operator()(size_t k, size_t s) const
{
const gt_hash_map<size_t,double>& nnks = _NNks.find(k)->second;
const typeof(nnks.begin()) iter = nnks.find(s);
const auto iter = nnks.find(s);
if (iter != nnks.end())
return iter->second;
return 0.0;
......
......@@ -52,7 +52,7 @@ struct get_community_network_vertices
for (auto vi : vertices_range(g))
{
s_type s = get(s_map, vi);
typeof(comms.begin()) iter = comms.find(s);
auto iter = comms.find(s);
cvertex_t v;
if (iter == comms.end())
{
......
......@@ -76,9 +76,11 @@ struct get_assortativity_coefficient
double t1 = double(e_kk) / n_edges, t2 = 0.0;
for (typeof(a.begin()) iter = a.begin(); iter != a.end(); ++iter)
if (b.find(iter->second) != b.end())
t2 += double(iter->second * b[iter->first]);
for (auto& ai : a)
{
if (b.find(ai.second) != b.end())
t2 += double(ai.second * b[ai.first]);
}
t2 /= n_edges*n_edges;
r = (t1 - t2)/(1.0 - t2);
......
......@@ -112,7 +112,7 @@ public:
size_t sum_out_deg = 0;
size_t j = 0;
for(typeof(d.begin()) di = d.begin(); di != d.end(); ++di)
for(auto di = d.begin(); di != d.end(); ++di)
{
size_t out_deg = di->first.second;
size_t count = di->second;
......@@ -121,12 +121,12 @@ public:
sum_out_deg += out_deg * count;
size_t sum_in_deg = 0;
typeof(d.begin()) dj_end = di; ++dj_end;
for(typeof(d.begin()) dj = d.begin(); dj != dj_end; ++dj)
sum_in_deg += min(dj->first.first, j - one)*dj->second;
auto dj_end = di; ++dj_end;
for(auto dj = d.begin(); dj != dj_end; ++dj)
sum_in_deg += min(dj->first.first, j - one) * dj->second;
size_t sum_rest = 0;
typeof(d.begin()) dj = di;
auto dj = di;
for(++dj; dj != d.end(); ++dj)
sum_rest += min(dj->first.first, j)*dj->second;
......@@ -142,9 +142,9 @@ public:
bool is_graphical_parallel(DegSequence& d)
{
size_t sum_in_deg = 0;
for(typeof(d.begin()) di = d.begin(); di != d.end(); ++di)
for(auto di = d.begin(); di != d.end(); ++di)
sum_in_deg += di->first.first * di->second;
for(typeof(d.begin()) di = d.begin(); di != d.end(); ++di)
for(auto di = d.begin(); di != d.end(); ++di)
{
if (di->first.second > sum_in_deg - di->first.first)
return false;
......@@ -194,8 +194,7 @@ public:
dvertex_t& v = vertices[i];
if (_no_parallel || _no_self_loops)
{
typeof(_deg_seq.begin()) iter =
_deg_seq.find(make_pair(v.in_degree, v.out_degree));
auto iter = _deg_seq.find(make_pair(v.in_degree, v.out_degree));
iter->second--;
if (iter->second == 0)
_deg_seq.erase(iter);
......@@ -263,12 +262,12 @@ public:
size_t one = (_no_self_loops) ? 1 : 0;
size_t sum_deg = 0;
size_t j = 0;
for(typeof(d.begin()) di = d.begin(); di != d.end(); ++di)
for(auto di = d.begin(); di != d.end(); ++di)
{
j += di->second;
sum_deg += di->first * di->second;
size_t sum_rest = 0;
typeof(d.begin()) dj = di;
auto dj = di;
for(++dj; dj != d.end(); ++dj)
sum_rest += min(dj->first, j)*dj->second;
if (sum_deg > j*(j-one) + sum_rest)
......@@ -283,11 +282,11 @@ public:
bool is_graphical_parallel(DegSequence& d)
{
size_t sum_deg = 0;
for(typeof(d.begin()) di = d.begin(); di != d.end(); ++di)
sum_deg += di->first * di->second;
for(typeof(d.begin()) di = d.begin(); di != d.end(); ++di)
for(auto& di : d)
sum_deg += di.first * di.second;
for(auto& di : d)
{
if (di->first > sum_deg - di->first)
if (di.first > sum_deg - di.first)
return false;
}
return true;
......@@ -335,7 +334,7 @@ public:
dvertex_t& v = vertices[i];
if (_no_parallel || _no_self_loops)
{
typeof(_deg_seq.begin()) iter = _deg_seq.find(v.out_degree);
auto iter = _deg_seq.find(v.out_degree);
iter->second--;
if(iter->second == 0)
_deg_seq.erase(iter);
......@@ -495,7 +494,7 @@ struct gen_graph
// find source. The out-degree must be non-zero, and there must be a
// vertex with the chosen degree.
deg_t s_deg = *sources.begin();
typeof(vset.begin()) sv_iter = vset.find(s_deg);
auto sv_iter = vset.find(s_deg);
if (s_deg.second == 0 || sv_iter == vset.end() ||
sv_iter->second.empty())
{
......@@ -519,8 +518,8 @@ struct gen_graph
// find the targets.
// we will keep an iterator to the current target degree
typeof(targets.begin()) t_iter = targets.begin();
typeof(vset.begin()) v_iter = vset.find(*t_iter);
auto t_iter = targets.begin();
auto v_iter = vset.find(*t_iter);
while (v_iter == vset.end() || v_iter->second.empty())
{
targets.erase(t_iter);
......
......@@ -148,7 +148,7 @@ struct get_geometric
if (periodic_boundary)
periodic(box, box_ranges);
typeof(boxes.begin()) iter, end;
decltype(boxes.begin()) iter, end;
for (tie(iter, end) = boxes.equal_range(box);
iter != end; ++iter)
{
......
......@@ -70,7 +70,7 @@ struct get_price
{
uniform_real_distribution<> sample(0, probs.rbegin()->first);
double r = sample(rng);
typeof(probs.begin()) iter = probs.lower_bound(r);
auto iter = probs.lower_bound(r);
typename graph_traits<Graph>::vertex_descriptor w =
iter->second;
......
......@@ -383,7 +383,7 @@ public:
: _g(g), _edge_index(edge_index), _edges(edges),
_vertices(HardNumVertices()(g)), _rng(rng)
{
typeof(_vertices.begin()) viter = _vertices.begin();
decltype(_vertices.begin()) viter = _vertices.begin();
typename graph_traits<Graph>::vertex_iterator v, v_end;
for (tie(v, v_end) = vertices(_g); v != v_end; ++v)
*(viter++) = *v;
......@@ -933,7 +933,7 @@ public:
~AliasProbabilisticRewireStrategy()
{
for (typeof(_sampler.begin()) iter = _sampler.begin();
for (decltype(_sampler.begin()) iter = _sampler.begin();
iter != _sampler.end(); ++iter)
delete iter->second;
}
......
......@@ -593,18 +593,13 @@ inline __attribute__((always_inline))
void remove_out_edge_if(typename graph_traits<UndirectedAdaptor<Graph> >::vertex_descriptor v,
Predicate predicate, UndirectedAdaptor<Graph>& g)
{
std::list<typename UndirectedAdaptor<Graph>::EdgeDescriptor> removed_edges;
typedef typename graph_traits<UndirectedAdaptor<Graph> >::out_edge_iterator
iter_t;
std::pair<iter_t, iter_t> edge_range;
edge_range = out_edges(v,g);
for(iter_t iter = edge_range.first; iter != edge_range.second; ++iter)
std::vector<typename UndirectedAdaptor<Graph>::EdgeDescriptor> removed_edges;
auto edge_range = out_edges(v,g);
for(auto iter = edge_range.first; iter != edge_range.second; ++iter)
if (predicate(*iter))
removed_edges.push_front(*iter);
for(typeof(removed_edges.begin()) iter = removed_edges.begin();
iter != removed_edges.end(); ++iter)
remove_edge(*iter,g);
removed_edges.push_back(*iter);
for(auto& e : removed_edges)
remove_edge(e, g);
}
//==============================================================================
......@@ -615,18 +610,13 @@ inline __attribute__((always_inline))
void remove_in_edge_if(typename graph_traits<UndirectedAdaptor<Graph> >::vertex_descriptor v,
Predicate predicate, UndirectedAdaptor<Graph>& g)
{
std::list<typename UndirectedAdaptor<Graph>::EdgeDescriptor> removed_edges;
typedef typename graph_traits<UndirectedAdaptor<Graph> >::in_edge_iterator
iter_t;
std::pair<iter_t, iter_t> edge_range;
edge_range = in_edges(v,g);
for(iter_t iter = edge_range.first; iter != edge_range.second; ++iter)
std::vector<typename UndirectedAdaptor<Graph>::EdgeDescriptor> removed_edges;
auto edge_range = in_edges(v,g);
for(auto iter = edge_range.first; iter != edge_range.second; ++iter)
if (predicate(*iter))
removed_edges.push_front(*iter);
for(typeof(removed_edges.begin()) iter = removed_edges.begin();
iter != removed_edges.end(); ++iter)
remove_edge(*iter,g);
removed_edges.push_back(*iter);
for(auto& e : removed_edges)
remove_edge(e, g);
}
......
......@@ -182,17 +182,14 @@ void GraphInterface::purge_edges()
return;
MaskFilter<edge_filter_t> filter(_edge_filter_map, _edge_filter_invert);
graph_traits<multigraph_t>::vertex_iterator v, v_end;
graph_traits<multigraph_t>::out_edge_iterator e, e_end;
vector<graph_traits<multigraph_t>::edge_descriptor> deleted_edges;
for (tie(v, v_end) = vertices(*_mg); v != v_end; ++v)
for (auto v : vertices_range(*_mg))
{
for (tie(e, e_end) = out_edges(*v, *_mg); e != e_end; ++e)
if (!filter(*e))
deleted_edges.push_back(*e);
for (typeof(deleted_edges.begin()) iter = deleted_edges.begin();
iter != deleted_edges.end(); ++iter)
remove_edge(*iter, *_mg);
for (auto e : out_edges_range(v, *_mg))
if (!filter(e))
deleted_edges.push_back(e);
for (auto& e : deleted_edges)
remove_edge(e, *_mg);
deleted_edges.clear();
}
}
......
......@@ -417,7 +417,7 @@ boost::python::tuple GraphInterface::read_from_file(string file,
}
else
{
for(typeof(dp.begin()) iter = dp.begin(); iter != dp.end(); ++iter)
for(auto iter = dp.begin(); iter != dp.end(); ++iter)
{
if (iter->second->key() == typeid(vertex_t))
vprops[iter->first] = find_property_map(*iter->second,
......@@ -452,8 +452,7 @@ string graphviz_insert_index(dynamic_properties& dp, IndexMap index_map,
{
typedef GraphInterface::vertex_t vertex_t;
bool found = false;
for(typeof(dp.begin()) iter = dp.begin(); iter != dp.end();
++iter)
for(auto iter = dp.begin(); iter != dp.end(); ++iter)
if (iter->first == "vertex_name" &&
iter->second->key() == typeid(vertex_t))
found = true;
......
......@@ -135,8 +135,7 @@ public:
else // arbitrary bins widths. do a binary search
{
std::vector<ValueType>& bins = _bins[i];
typeof(bins.begin()) iter = upper_bound(bins.begin(),
bins.end(), v[i]);
auto iter = upper_bound(bins.begin(), bins.end(), v[i]);
if (iter == bins.end())
{
return; // falls off from last bin, do not count
......@@ -234,10 +233,10 @@ double get_map_mean(const Map &m)
{
int total = 0;
double mean = 0;
for (typeof(m.begin()) iter = m.begin(); iter != m.end(); iter++)
for (auto& vc : m)
{
mean += double(iter->first * iter->second);
total += iter->second;
mean += double(vc.first * vc.second);
total += vc.second;
}
return (total > 0)?mean/total:0.0;
......@@ -249,11 +248,10 @@ double get_map_deviation(const Map &m, double avg)
{
double dev = 0.0;
int total = 0;
for (typeof(m.begin()) iter = m.begin(); iter != m.end(); iter++)
for (auto& vc : m)
{
dev += double( (iter->first - avg) *
(iter->first - avg) * iter->second);
total += iter->second;
dev += double((vc.first - avg) * (vc.first - avg) * vc.second);
total += vc.second;
}
return (total > 1)?sqrt(dev/(total-1)):0.0;
}
......
......@@ -50,13 +50,13 @@ struct do_astar_search
dtype_t z = python::extract<dtype_t>(range.first);
dtype_t i = python::extract<dtype_t>(range.second);
typedef typename property_map_type::
apply<int32_t, typeof(get(vertex_index, g))>::type pred_t;
apply<int32_t, decltype(get(vertex_index, g))>::type pred_t;
pred_t pred = any_cast<pred_t>(pred_map);
checked_vector_property_map<default_color_type,
typeof(get(vertex_index, g))>
decltype(get(vertex_index, g))>
color(get(vertex_index, g));
checked_vector_property_map<dtype_t,
typeof(get(vertex_index, g))>
decltype(get(vertex_index, g))>
cost(get(vertex_index, g));
DynamicPropertyMapWrap<dtype_t, edge_t> weight(aweight,
edge_properties());
......
......@@ -47,10 +47,10 @@ struct do_astar_search
dtype_t i = python::extract<dtype_t>(range.second);
checked_vector_property_map<default_color_type,
typeof(get(vertex_index, g))>
decltype(get(vertex_index, g))>
color(get(vertex_index, g));
typedef typename property_map_type::
apply<int32_t, typeof(get(vertex_index, g))>::type pred_t;
apply<int32_t, decltype(get(vertex_index, g))>::type pred_t;
typedef typename graph_traits<Graph>::edge_descriptor edge_t;
DynamicPropertyMapWrap<dtype_t, edge_t> weight(aweight,
edge_properties());
......
......@@ -125,7 +125,7 @@ struct do_bf_search
dtype_t i = python::extract<dtype_t>(range.second);
typedef typename property_map_type::
apply<int32_t, typeof(get(vertex_index, g))>::type pred_t;
apply<int32_t, decltype(get(vertex_index, g))>::type pred_t;
pred_t pred = any_cast<pred_t>(pred_map);
typedef typename graph_traits<Graph>::edge_descriptor edge_t;
DynamicPropertyMapWrap<dtype_t, edge_t> weight(aweight,
......
......@@ -133,7 +133,7 @@ struct do_djk_search
dtype_t z = python::extract<dtype_t>(range.first);
dtype_t i = python::extract<dtype_t>(range.second);
typedef typename property_map_type::
apply<int32_t, typeof(get(vertex_index, g))>::type pred_t;
apply<int32_t, decltype(get(vertex_index, g))>::type pred_t;
pred_t pred = any_cast<pred_t>(pred_map);
typedef typename graph_traits<Graph>::edge_descriptor edge_t;
DynamicPropertyMapWrap<dtype_t, edge_t> weight(aweight,
......@@ -153,7 +153,7 @@ void dijkstra_search(GraphInterface& g, size_t source, boost::any dist_map,
python::object zero, python::object inf)
{
run_action<graph_tool::detail::all_graph_views,mpl::true_>()
(g, std::bind(do_djk_search(), placeholders::_1, source,
(g, std::bind(do_djk_search(), placeholders::_1, source,
placeholders::_2, pred_map, weight,
DJKVisitorWrapper(g, vis), DJKCmp(cmp), DJKCmb(cmb),
make_pair(zero, inf)),
......
......@@ -37,7 +37,7 @@ public:
{
if (_sum != 0)
{
for (typeof(this->begin()) iter = this->begin();
for (decltype(this->begin()) iter = this->begin();
iter != this->end(); ++iter)
{
#pragma omp critical
......@@ -71,13 +71,10 @@ public:
{
if (_sum != 0)
{
for (typeof(this->begin()) iter = this->begin();
iter != this->end(); ++iter)
#pragma omp critical
{
#pragma omp critical
{
_sum->push_back(*iter);
}
for (auto& x : *this)
_sum->push_back(x);
}
_sum = 0;
}
......
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