$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r53347 - sandbox/SOC/2009/function_graph/boost/function_graph
From: asutton_at_[hidden]
Date: 2009-05-28 13:13:06
Author: asutton
Date: 2009-05-28 13:13:05 EDT (Thu, 28 May 2009)
New Revision: 53347
URL: http://svn.boost.org/trac/boost/changeset/53347
Log:
Adding proper specializations.
Text files modified: 
   sandbox/SOC/2009/function_graph/boost/function_graph/function_graph.hpp |    73 +++++++++++++++++++++++---------------- 
   1 files changed, 43 insertions(+), 30 deletions(-)
Modified: sandbox/SOC/2009/function_graph/boost/function_graph/function_graph.hpp
==============================================================================
--- sandbox/SOC/2009/function_graph/boost/function_graph/function_graph.hpp	(original)
+++ sandbox/SOC/2009/function_graph/boost/function_graph/function_graph.hpp	2009-05-28 13:13:05 EDT (Thu, 28 May 2009)
@@ -1,10 +1,10 @@
 /**
  * Copyright (C) 2009
  * Michael Lopez
- * 
+ *
  * Issued under Boost Software License - Version 1.0
  * http://www.boost.org/LICENSE_1_0.txt
- * 
+ *
  */
 
 
@@ -18,49 +18,62 @@
 
 namespace boost { namespace graph {
 
+// [asutton] You're going about this in slightly the wrong way...
+
 /**
  * function_graph_base handles the edge function. A user can define the function
  * through a boost::function or a functor, but the user must only have access to
  * this function through function graph via the function edge.
+ *
+ * @note [asutton] Don't try to deduce what might be passed to this function.
+ * Just require that F be of the form boost::function<R,T,T>. Use the derived
+ * classes to put the type in the right form.
  */
-
-template <typename F>
+template <typename Func>
 struct function_graph_base {
     // If the type F has an arity of 2, then it is the boost function syntax.
     // Otherwise, this function is either a functor or a boost function that is
     // already defined.
-    typedef typename mpl::if_c<function_types::function_arity<F>::value == 2,
-                               function<F>,
-                               F>::type func_type;
-    /** Types are deduced from F */
-    
+//     typedef typename mpl::if_c<function_types::function_arity<F>::value == 2,
+//                                function<F>,
+//                                F>::type func_type;
+
+    typedef Func function_type;
+    typedef typename Func::result_type edge_type;
+    typedef typename Func::argument_type vertex_type;
+
     /** Edge function that defines the implicit graph */
-    func_type edge;
+    function_type func;
 };
 
+/**
+ * @note [asutton] I'm defining an empty function graph so that we can create
+ * specializations that force the user to provide T in certain forms. This
+ * variant will be instantiated for meaningless types such as graph<int>.
+ * Obviously, that should fail.
+ */
+template <typename T> struct functon_graph { };
 
 /**
- * function_graph is a data structure that creates an implicit graph based on a
- * function or functor that is either user defined or from the stl or boost.
- * 
- * For a more enlightening explanation, please refer to the documentation. 
- * 
- * @todo
- * Supply polished documentation
- * Implement domain and range
- * Implement an edge iterator
+ * @note [asutton] This specialization will be instantiated whenever the
+ * user tries to make something like graph< function<bool(int,int)> >. Note
+ * the subtelty. If you write: graph<function<bool(int, double)> >, then
+ * the compiler will match the version above, causing compiler errors.
  */
- 
-template<typename F>
-class function_graph : private function_graph_base<F>
-{
-    typedef function_graph_base<F> Base;
-public:
-
-    /** The edge function. */
-    using Base::edge;
-    
-};
+template <typename Edge, typename Vertex>
+struct function_graph< function<Edge(Vertex, Vertex)> >
+    : function_graph_base< function<Edge(Vertex, Vertex)> >
+{ };
+
+/**
+ * @note This specialization will match any function of the form E(V,V) and
+ * generates the graph over an adapted boost function. Note that functions of
+ * the form E(U,V) will match the empty class causing compiler errors.
+ *
+template <typename Edge, typename Vertex>
+struct fucntion_graph<Edge(Vertex, Vertex)>
+    : function_graph_base< function<Edge(Vertex, Vertex)> >
+{ };
 
 }   // graph namespace
 }   // boost namespace