Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r84028 - in trunk: boost/graph libs/graph/test
From: jewillco_at_[hidden]
Date: 2013-04-23 22:19:14


Author: jewillco
Date: 2013-04-23 22:19:13 EDT (Tue, 23 Apr 2013)
New Revision: 84028
URL: http://svn.boost.org/trac/boost/changeset/84028

Log:
Added support for distance types without numeric_limits specializations; changed test to use that functionality to ensure that it keeps working; fixes #8490
Text files modified:
   trunk/boost/graph/astar_search.hpp | 8 ++++----
   trunk/boost/graph/named_function_params.hpp | 10 ++++++++++
   trunk/libs/graph/test/astar_search_test.cpp | 19 ++++++++++++-------
   3 files changed, 26 insertions(+), 11 deletions(-)

Modified: trunk/boost/graph/astar_search.hpp
==============================================================================
--- trunk/boost/graph/astar_search.hpp (original)
+++ trunk/boost/graph/astar_search.hpp 2013-04-23 22:19:13 EDT (Tue, 23 Apr 2013)
@@ -438,7 +438,7 @@
       typename detail::map_maker<VertexListGraph, arg_pack_type, tag::distance_map, W>::map_type
       distance_map_type;
     typedef typename boost::property_traits<distance_map_type>::value_type D;
- const D inf = arg_pack[_distance_inf | (std::numeric_limits<D>::max)()];
+ const D inf = arg_pack[_distance_inf || detail::get_max<D>()];
 
     astar_search
       (g, s, h,
@@ -480,7 +480,7 @@
       typename detail::map_maker<VertexListGraph, arg_pack_type, tag::distance_map, W>::map_type
       distance_map_type;
     typedef typename boost::property_traits<distance_map_type>::value_type D;
- const D inf = arg_pack[_distance_inf | (std::numeric_limits<D>::max)()];
+ const D inf = arg_pack[_distance_inf || detail::get_max<D>()];
 
     astar_search_tree
       (g, s, h,
@@ -512,7 +512,7 @@
                  arg_pack_type, tag::weight_map, edge_weight_t, VertexListGraph>::type
                weight_map_type;
     typedef typename boost::property_traits<weight_map_type>::value_type D;
- const D inf = arg_pack[_distance_inf | (std::numeric_limits<D>::max)()];
+ const D inf = arg_pack[_distance_inf || detail::get_max<D>()];
     astar_search_no_init
       (g, s, h,
        arg_pack[_visitor | make_astar_visitor(null_visitor())],
@@ -545,7 +545,7 @@
                  arg_pack_type, tag::weight_map, edge_weight_t, VertexListGraph>::type
                weight_map_type;
     typedef typename boost::property_traits<weight_map_type>::value_type D;
- const D inf = arg_pack[_distance_inf | (std::numeric_limits<D>::max)()];
+ const D inf = arg_pack[_distance_inf || detail::get_max<D>()];
     astar_search_no_init_tree
       (g, s, h,
        arg_pack[_visitor | make_astar_visitor(null_visitor())],

Modified: trunk/boost/graph/named_function_params.hpp
==============================================================================
--- trunk/boost/graph/named_function_params.hpp (original)
+++ trunk/boost/graph/named_function_params.hpp 2013-04-23 22:19:13 EDT (Tue, 23 Apr 2013)
@@ -12,6 +12,7 @@
 
 #include <functional>
 #include <vector>
+#include <boost/limits.hpp>
 #include <boost/ref.hpp>
 #include <boost/utility/result_of.hpp>
 #include <boost/preprocessor.hpp>
@@ -718,6 +719,15 @@
       result_type operator()() const {return get_default_starting_vertex(g);}
     };
 
+ // Wrapper to avoid instantiating numeric_limits when users provide distance_inf value manually
+ template <typename T>
+ struct get_max {
+ T operator()() const {
+ return (std::numeric_limits<T>::max)();
+ }
+ typedef T result_type;
+ };
+
   } // namespace detail
 
 } // namespace boost

Modified: trunk/libs/graph/test/astar_search_test.cpp
==============================================================================
--- trunk/libs/graph/test/astar_search_test.cpp (original)
+++ trunk/libs/graph/test/astar_search_test.cpp 2013-04-23 22:19:13 EDT (Tue, 23 Apr 2013)
@@ -31,7 +31,12 @@
 {
   float y, x; // lat, long
 };
-typedef float cost;
+struct my_float {float v; explicit my_float(float v = float()): v(v) {}};
+typedef my_float cost;
+ostream& operator<<(ostream& o, my_float f) {return o << f.v;}
+my_float operator+(my_float a, my_float b) {return my_float(a.v + b.v);}
+bool operator==(my_float a, my_float b) {return a.v == b.v;}
+bool operator<(my_float a, my_float b) {return a.v < b.v;}
 
 template <class Name, class LocMap>
 class city_writer {
@@ -80,9 +85,9 @@
     : m_location(l), m_goal(goal) {}
   CostType operator()(Vertex u)
   {
- CostType dx = m_location[m_goal].x - m_location[u].x;
- CostType dy = m_location[m_goal].y - m_location[u].y;
- return ::sqrt(dx * dx + dy * dy);
+ float dx = m_location[m_goal].x - m_location[u].x;
+ float dy = m_location[m_goal].y - m_location[u].y;
+ return CostType(::sqrt(dx * dx + dy * dy));
   }
 private:
   LocMap m_location;
@@ -153,8 +158,8 @@
   };
   unsigned int num_edges = sizeof(edge_array) / sizeof(edge);
   cost weights[] = { // estimated travel time (mins)
- 96, 134, 143, 65, 115, 133, 117, 116, 74, 56,
- 84, 73, 69, 70, 116, 147, 173, 183, 74, 71, 124
+ my_float(96), my_float(134), my_float(143), my_float(65), my_float(115), my_float(133), my_float(117), my_float(116), my_float(74), my_float(56),
+ my_float(84), my_float(73), my_float(69), my_float(70), my_float(116), my_float(147), my_float(173), my_float(183), my_float(74), my_float(71), my_float(124)
   };
   
   
@@ -187,7 +192,7 @@
        distance_heuristic<mygraph_t, cost, location*>
         (locations, goal),
        predecessor_map(&p[0]).distance_map(&d[0]).
- visitor(astar_goal_visitor<vertex>(goal)));
+ visitor(astar_goal_visitor<vertex>(goal)).distance_inf(my_float((std::numeric_limits<float>::max)())));
   
   
   } catch(found_goal fg) { // found a path to the goal


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk