Commits (3)
......@@ -21,10 +21,6 @@
#include <boost/graph/breadth_first_search.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>
#include <boost/python/object.hpp>
#include <boost/python/list.hpp>
#include <boost/python/extract.hpp>
#include "histogram.hh"
#include "hash_map_wrap.hh"
......
......@@ -25,8 +25,6 @@
#include "graph_avg_correlations.hh"
#include <iostream>
using namespace std;
using namespace boost;
using namespace graph_tool;
......
......@@ -21,12 +21,8 @@
#include <algorithm>
#include <boost/numeric/conversion/bounds.hpp>
#include <boost/numeric/conversion/cast.hpp>
#include <boost/python/object.hpp>
#include <boost/python/list.hpp>
#include <boost/python/extract.hpp>
#include "histogram.hh"
#include "numpy_bind.hh"
#include "shared_map.hh"
namespace graph_tool
{
......
......@@ -22,7 +22,6 @@
#include "graph_filtering.hh"
#include <boost/python.hpp>
#include <boost/utility/enable_if.hpp>
#include "graph_selectors.hh"
#include "graph_properties.hh"
......
......@@ -22,7 +22,6 @@
#include "graph_selectors.hh"
#include "graph_properties.hh"
#include <boost/mpl/quote.hpp>
#include <boost/graph/breadth_first_search.hpp>
#include <cmath>
......
......@@ -21,7 +21,6 @@
#include "graph.hh"
#include "graph_filtering.hh"
#include "graph_util.hh"
#include "graph_python_interface.hh"
#ifdef _OPENMP
#include <omp.h>
#endif
......
......@@ -21,7 +21,6 @@
#include "graph_selectors.hh"
#include "graph_properties.hh"
#include <boost/bind/placeholders.hpp>
#include <boost/mpl/push_back.hpp>
#include <boost/python.hpp>
......
......@@ -21,7 +21,6 @@
#include "graph_selectors.hh"
#include "graph_properties.hh"
#include <boost/bind/placeholders.hpp>
#include <boost/mpl/push_back.hpp>
#include <boost/python.hpp>
......
......@@ -21,7 +21,6 @@
#include "graph_selectors.hh"
#include "graph_properties.hh"
#include <boost/bind/placeholders.hpp>
#include <boost/mpl/push_back.hpp>
#include <boost/python.hpp>
......
......@@ -21,7 +21,6 @@
#include "graph_selectors.hh"
#include "graph_properties.hh"
#include <boost/bind/placeholders.hpp>
#include <boost/mpl/push_back.hpp>
#include <boost/python.hpp>
......
......@@ -21,7 +21,6 @@
#include "graph_selectors.hh"
#include "graph_properties.hh"
#include <boost/bind/placeholders.hpp>
#include <boost/mpl/push_back.hpp>
#include <boost/python.hpp>
......
......@@ -20,8 +20,6 @@
#include <tuple>
#include <iostream>
#include <boost/functional/hash.hpp>
#include <boost/multi_array.hpp>
#include "graph.hh"
#include "graph_filtering.hh"
......
......@@ -21,8 +21,6 @@
#include "graph_union.hh"
#include <boost/python/extract.hpp>
using namespace graph_tool;
using namespace boost;
......
......@@ -20,9 +20,6 @@
#include "graph_union.hh"
#include <boost/python/extract.hpp>
using namespace graph_tool;
using namespace boost;
......
......@@ -29,7 +29,6 @@
#include <boost/variant/get.hpp>
#include <boost/spirit/include/support_istream_iterator.hpp>
#include <boost/foreach.hpp>
#include <boost/type_traits.hpp>
#include <boost/algorithm/string/replace.hpp>
......@@ -44,7 +43,6 @@
#include <fstream>
#include <string>
#include <vector>
#include <unordered_map>
#include "base64.hh"
......
......@@ -21,7 +21,6 @@
#include <boost/lambda/lambda.hpp>
#include <boost/lambda/bind.hpp>
#include <iostream>
using namespace std;
using namespace boost;
......
......@@ -19,11 +19,11 @@
#define GRAPH_HH
#include "config.h"
#include <Python.h>
#include <boost/python/object.hpp>
#include <boost/python/dict.hpp>
#include <boost/python/list.hpp>
#include <boost/python/tuple.hpp>
#include <deque>
#include <boost/any.hpp>
#include "graph_adjacency.hh"
......@@ -31,7 +31,7 @@
#include "fast_vector_property_map.hh"
#include <boost/variant.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/bool_fwd.hpp>
#include "graph_properties.hh"
#include "graph_exceptions.hh"
......
......@@ -22,7 +22,6 @@
#include <deque>
#include <utility>
#include <numeric>
#include <iostream>
#include <tuple>
#include <boost/iterator.hpp>
#include <boost/graph/graph_traits.hpp>
......
......@@ -21,7 +21,6 @@
#include "graph_selectors.hh"
#include <boost/mpl/for_each.hpp>
#include <boost/mpl/contains.hpp>
#include <boost/python/extract.hpp>
using namespace std;
......
......@@ -22,31 +22,14 @@
#include <boost/version.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/erase.hpp>
#include <boost/mpl/clear.hpp>
#include <boost/mpl/map.hpp>
#include <boost/mpl/for_each.hpp>
#include <boost/mpl/at.hpp>
#include <boost/mpl/or.hpp>
#include <boost/mpl/if.hpp>
#include <boost/mpl/logical.hpp>
#include <boost/mpl/inserter.hpp>
#include <boost/mpl/insert_range.hpp>
#include <boost/mpl/back_inserter.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/mpl/plus.hpp>
#include <boost/mpl/divides.hpp>
#include <boost/mpl/arithmetic.hpp>
#include <boost/mpl/greater_equal.hpp>
#include <boost/mpl/comparison.hpp>
#include <boost/mpl/transform_view.hpp>
#include <boost/mpl/quote.hpp>
#include <boost/mpl/range_c.hpp>
#include <boost/mpl/print.hpp>
#include "graph_adaptor.hh"
#include "graph_filtered.hh"
#include "graph_reverse.hh"
#include "graph_selectors.hh"
#include "graph_util.hh"
#include "mpl_nested_loop.hh"
......@@ -440,9 +423,83 @@ struct action_wrap
Action _a;
};
// this takes a functor and type ranges and iterates through the type
// combinations when called with boost::any parameters, and calls the correct
// function
//
// action_dispatch machinery
//
// a lightweight class for holding a list of types
template <class... T>
struct typelist {};
template <class... T>
constexpr auto to_typelist(std::tuple<T...>) -> typelist<T...>;
template <class Tuple>
using to_typelist_t = decltype(to_typelist(std::declval<Tuple>()));
// handling one typelist/value
// select a binding from the current list
template<class F, // function to bind
class... Ts, // current typelist
class... TRS, // remaining typelists
class Arg,
class... Args>
bool dispatch_loop(F f,
typelist<typelist<Ts...>, TRS...>,
Arg&& arg,
Args&&... args) // remaining args
{
using namespace boost::mpl;
// determine which one of the Ts we are looking at
// then recurse with the first argument of F bound accordingly
void *farg; // pointer to extracted value from boost::any
// we always will know what its type is
if constexpr (sizeof...(TRS) == 0)
{
// just one argument remains to be bound
return (
// iterate over types, trying each
((farg = boost::any_cast<Ts>(&arg))
? (f(*static_cast<Ts*>(farg)), true)
// try reference_wrapper instead
: ((farg = boost::any_cast<std::reference_wrapper<Ts>>(&arg))
? (f(static_cast<std::reference_wrapper<Ts>*>(farg)->get()), true)
: false)) || ...);
}
else
{
// helper function for setting up recursion
auto dl =
[f = std::move(f)](auto * a, // extracted value from boost::any
auto&&... args) // boost::any's yet to be processed
{
// create the new F with N-1 arguments
return dispatch_loop
([f = std::move(f), a](auto &&... fargs){
f(*a,
std::forward<decltype(fargs)>(fargs)...);
},
typelist<TRS...>{},
std::forward<decltype(args)>(args)...);
};
return (
((farg = boost::any_cast<Ts>(&arg))
? dl(static_cast<Ts*>(farg),
std::forward<Args>(args)...)
: ((farg = boost::any_cast<std::reference_wrapper<Ts>>(&arg))
? dl(&static_cast<std::reference_wrapper<Ts>*>(farg)->get(),
std::forward<Args>(args)...)
: false))
|| ...); // iterate over Ts...
}
}
// this takes a functor and type ranges, locates the correct combination
// from the boost::any parameters, and calls the correct function
template <class Action, class Wrap, class... TRS>
struct action_dispatch
{
......@@ -451,8 +508,11 @@ struct action_dispatch
template <class... Args>
void operator()(Args&&... args) const
{
bool found =
boost::mpl::nested_for_each<TRS...>(_a, std::forward<Args>(args)...);
using namespace boost::mpl;
bool found = dispatch_loop(_a, typelist<to_typelist_t<to_tuple_t<TRS>>...>{},
std::forward<Args>(args)...);
if (!found)
{
std::vector<const std::type_info*> args_t = {(&(args).type())...};
......