From ebdec45c4b7e271cc946900efd9648743b6ceb60 Mon Sep 17 00:00:00 2001 From: Jeremiah Willcock Date: Mon, 16 Apr 2012 18:44:36 +0000 Subject: [PATCH] Added test for Boost.Parameter version of isomorphism; fixed bugs that found [SVN r78024] --- include/boost/graph/breadth_first_search.hpp | 3 +- include/boost/graph/depth_first_search.hpp | 3 +- include/boost/graph/isomorphism.hpp | 3 +- include/boost/graph/named_function_params.hpp | 42 ++++++++++++++----- test/isomorphism.cpp | 10 +++-- 5 files changed, 43 insertions(+), 18 deletions(-) diff --git a/include/boost/graph/breadth_first_search.hpp b/include/boost/graph/breadth_first_search.hpp index 80683204..703f6c35 100644 --- a/include/boost/graph/breadth_first_search.hpp +++ b/include/boost/graph/breadth_first_search.hpp @@ -373,9 +373,10 @@ namespace boost { namespace graph { namespace detail { - template + template struct breadth_first_search_impl { typedef void result_type; + template void operator()(const Graph& g, const Source& source, const ArgPack& arg_pack) { using namespace boost::graph::keywords; typename boost::graph_traits::vertex_descriptor sources[1] = {source}; diff --git a/include/boost/graph/depth_first_search.hpp b/include/boost/graph/depth_first_search.hpp index c5ce5053..e8f21b4e 100644 --- a/include/boost/graph/depth_first_search.hpp +++ b/include/boost/graph/depth_first_search.hpp @@ -286,9 +286,10 @@ namespace boost { // Boost.Parameter named parameter variant namespace graph { namespace detail { - template + template struct depth_first_search_impl { typedef void result_type; + template void operator()(const Graph& g, const ArgPack& arg_pack) const { using namespace boost::graph::keywords; boost::depth_first_search(g, diff --git a/include/boost/graph/isomorphism.hpp b/include/boost/graph/isomorphism.hpp index 31fc0c32..1aa415fd 100644 --- a/include/boost/graph/isomorphism.hpp +++ b/include/boost/graph/isomorphism.hpp @@ -491,9 +491,10 @@ fi_adj_loop_k:++fi_adj.first; namespace graph { namespace detail { - template + template struct isomorphism_impl { typedef bool result_type; + template bool operator()(const Graph1& g1, const Graph2& g2, const ArgPack& arg_pack) const { using namespace boost::graph::keywords; typedef typename boost::detail::override_const_property_result::type index1_map_type; diff --git a/include/boost/graph/named_function_params.hpp b/include/boost/graph/named_function_params.hpp index 2eda0e87..e19ffef1 100644 --- a/include/boost/graph/named_function_params.hpp +++ b/include/boost/graph/named_function_params.hpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -464,12 +465,34 @@ BOOST_BGL_DECLARE_NAMED_PARAMS >()(g, ap[t | 0]); } + template struct make_arg_pack_type; + template <> struct make_arg_pack_type {typedef boost::parameter::aux::empty_arg_list type;}; + template + struct make_arg_pack_type { + typedef boost::parameter::aux::tagged_argument type; + }; + +#define BOOST_GRAPH_OPENING_PART_OF_PAIR(z, i, n) boost::parameter::aux::arg_list, +#define BOOST_GRAPH_MAKE_PAIR_PARAM(z, i, _) const boost::parameter::aux::tagged_argument& BOOST_PP_CAT(kw, i) + +#define BOOST_GRAPH_MAKE_AP_TYPE_SPECIALIZATION(z, i, _) \ + template \ + struct make_arg_pack_type { \ + typedef \ + BOOST_PP_REPEAT(i, BOOST_GRAPH_OPENING_PART_OF_PAIR, BOOST_PP_DEC(i)) boost::parameter::aux::empty_arg_list BOOST_PP_REPEAT(i, > BOOST_PP_TUPLE_EAT(3), ~) \ + type; \ + }; + BOOST_PP_REPEAT_FROM_TO(2, 11, BOOST_GRAPH_MAKE_AP_TYPE_SPECIALIZATION, ~) +#undef BOOST_GRAPH_MAKE_AP_TYPE_SPECIALIZATION + #define BOOST_GRAPH_MAKE_FORWARDING_FUNCTION(name, nfixed, nnamed_max) \ /* Entry point for conversion from BGL-style named parameters */ \ template \ - typename detail::BOOST_PP_CAT(name, _impl)::result_type \ + typename boost::result_of< \ + detail::BOOST_PP_CAT(name, _impl)(BOOST_PP_ENUM_PARAMS(nfixed, Param) BOOST_PP_COMMA_IF(nfixed) const ArgPack&) \ + >::type \ BOOST_PP_CAT(name, _with_named_params)(BOOST_PP_ENUM_BINARY_PARAMS(nfixed, const Param, & param) BOOST_PP_COMMA_IF(nfixed) const ArgPack& arg_pack) { \ - return detail::BOOST_PP_CAT(name, _impl)()(BOOST_PP_ENUM_PARAMS(nfixed, param) BOOST_PP_COMMA_IF(nfixed) arg_pack); \ + return detail::BOOST_PP_CAT(name, _impl)()(BOOST_PP_ENUM_PARAMS(nfixed, param) BOOST_PP_COMMA_IF(nfixed) arg_pack); \ } \ /* Individual functions taking Boost.Parameter-style keyword arguments */ \ BOOST_PP_REPEAT(BOOST_PP_INC(nnamed_max), BOOST_GRAPH_MAKE_FORWARDING_FUNCTION_ONE, (name)(nfixed)) @@ -479,21 +502,18 @@ BOOST_BGL_DECLARE_NAMED_PARAMS #define BOOST_GRAPH_MAKE_FORWARDING_FUNCTION_ONEX(z, nnamed, name, nfixed) \ template \ - typename detail::BOOST_PP_CAT(name, _impl)::result_type \ + typename boost::result_of< \ + detail::BOOST_PP_CAT(name, _impl) \ + (BOOST_PP_ENUM_PARAMS(nfixed, Param) BOOST_PP_COMMA_IF(nfixed) \ + const typename boost::detail::make_arg_pack_type::type&) \ + >::type \ name(BOOST_PP_ENUM_BINARY_PARAMS(nfixed, const Param, & param) \ BOOST_PP_ENUM_TRAILING(nnamed, BOOST_GRAPH_MAKE_PAIR_PARAM, ~)) { \ - return detail::BOOST_PP_CAT(name, _impl)() \ + return detail::BOOST_PP_CAT(name, _impl)() \ (BOOST_PP_ENUM_PARAMS(nfixed, param), \ (boost::parameter::aux::empty_arg_list() BOOST_PP_ENUM_TRAILING_PARAMS(nnamed, kw))); \ } -#define BOOST_GRAPH_TEMPLATE_ARGS_FOR_IMPL(nnamed, nfixed) \ - BOOST_PP_ENUM_PARAMS(nfixed, Param), \ - BOOST_PP_REPEAT(nnamed, BOOST_GRAPH_OPENING_PART_OF_PAIR, BOOST_PP_DEC(nnamed)) boost::parameter::aux::empty_arg_list BOOST_PP_REPEAT(nnamed, > BOOST_PP_TUPLE_EAT(3), ~) - -#define BOOST_GRAPH_OPENING_PART_OF_PAIR(z, i, n) boost::parameter::aux::arg_list, -#define BOOST_GRAPH_MAKE_PAIR_PARAM(z, i, _) const boost::parameter::aux::tagged_argument& BOOST_PP_CAT(kw, i) - } namespace detail { diff --git a/test/isomorphism.cpp b/test/isomorphism.cpp index a151cca1..fee22a21 100644 --- a/test/isomorphism.cpp +++ b/test/isomorphism.cpp @@ -95,6 +95,7 @@ void generate_random_digraph(Graph& g, double edge_probability) void test_isomorphism2() { + using namespace boost::graph::keywords; typedef adjacency_list graph1; typedef adjacency_list > graph2; @@ -115,8 +116,8 @@ void test_isomorphism2() bool isomorphism_correct; clock_t start = clock(); - BOOST_CHECK(isomorphism_correct = isomorphism - (g1, g2, isomorphism_map(make_assoc_property_map(mapping)))); + BOOST_CHECK(isomorphism_correct = boost::graph::isomorphism + (g1, g2, _isomorphism_map = make_assoc_property_map(mapping))); clock_t end = clock(); std::cout << "Elapsed time (clock cycles): " << (end - start) << std::endl; @@ -152,6 +153,7 @@ void test_isomorphism2() void test_isomorphism(int n, double edge_probability) { + using namespace boost::graph::keywords; typedef adjacency_list graph1; typedef adjacency_list > graph2; @@ -171,8 +173,8 @@ void test_isomorphism(int n, double edge_probability) bool isomorphism_correct; clock_t start = clock(); - BOOST_CHECK(isomorphism_correct = isomorphism - (g1, g2, isomorphism_map(make_assoc_property_map(mapping)))); + BOOST_CHECK(isomorphism_correct = boost::graph::isomorphism + (g1, g2, _isomorphism_map = make_assoc_property_map(mapping))); clock_t end = clock(); std::cout << "Elapsed time (clock cycles): " << (end - start) << std::endl;