Opened 12 years ago

Closed 12 years ago

Last modified 12 years ago

#4715 closed Bugs (fixed)

custom property_map no longer works for astar_search

Reported by: Szymon Gatner <szymon.gatner@…> Owned by: Jeremiah Willcock
Milestone: To Be Determined Component: graph
Version: Boost 1.44.0 Severity: Problem
Keywords: Cc:

Description

After updating from boost 1.43 to 1.44 code calling astar_search with custom property map no longer compiles with error:

Error 2 error C2039: 'value_type' : is not a member of 'boost::property_traits<PA>' c:\libs\boost_1_44_0\boost\graph\astar_search.hpp 323

dijkstra_shortest_paths_no_color_map() with same property map still compiles correctly.

custom property map:

template <typename Functor, typename Arg>
struct function_property_map {
private:
  Functor f;

public:
  typedef typename boost::property_traits<
    function_property_map<Functor, Arg>
  >::value_type
  value_type; 

  explicit function_property_map(const Functor& f): f(f) {}

  friend value_type get(const function_property_map& pm, const Arg& x) {
    return pm.f(x);
  }
};

namespace boost {
  template <typename Functor, typename Arg>
  struct property_traits<function_property_map<Functor, Arg> > {
    typedef typename boost::result_of<Functor(Arg)>::type value_type;
    typedef value_type reference;
    typedef Arg key_type;
    typedef boost::readable_property_map_tag category;
  };
}

template <typename Arg, typename Functor>
function_property_map<Functor, Arg>
make_function_property_map(const Functor& f) {
  return function_property_map<Functor, Arg>(f);
}

Attachments (2)

main.cpp (2.7 KB ) - added by Szymon Gatner <szymon.gatner@…> 12 years ago.
BuildLog.htm (13.0 KB ) - added by Szymon Gatner <szymon.gatner@…> 12 years ago.

Download all attachments as: .zip

Change History (19)

comment:1 by Szymon Gatner <szymon.gatner@…>, 12 years ago

Component: Nonegraph
Owner: set to Andrew Sutton

comment:2 by Jeremiah Willcock, 12 years ago

Owner: changed from Andrew Sutton to Jeremiah Willcock

comment:3 by Jeremiah Willcock, 12 years ago

Could you please attach the full instantiation stack and/or a complete piece of code to test?

by Szymon Gatner <szymon.gatner@…>, 12 years ago

Attachment: main.cpp added

comment:4 by Szymon Gatner <szymon.gatner@…>, 12 years ago

Extracted code for test. Also, I forgot to mention that I am building with Visual Studio 2008 SP1.

comment:5 by Jeremiah Willcock, 12 years ago

Resolution: worksforme
Status: newclosed

In my testing, you just need an extra include:

#include <boost/utility/result_of.hpp>

and then it compiles fine with GCC 4.1.2 and the Boost trunk.

Last edited 12 years ago by Jeremiah Willcock (previous) (diff)

comment:6 by Szymon Gatner <szymon.gatner@…>, 12 years ago

This does not work for me and in fact original code had that file included.

Even replacing

namespace boost {
  template <typename Functor, typename Arg>
  struct property_traits<function_property_map<Functor, Arg> > {
    typedef typename boost::result_of<Functor(Arg)>::type value_type;
    typedef value_type reference;
    typedef Arg key_type;
    typedef boost::readable_property_map_tag category;
  };
}

with

namespace boost {
  template <typename Functor, typename Arg>
  struct property_traits<function_property_map<Functor, Arg> > {
    typedef int value_type;
    typedef value_type reference;
    typedef Arg key_type;
    typedef boost::readable_property_map_tag category;
  };
}

results with same error

comment:7 by Jeremiah Willcock, 12 years ago

What needs to be changed is the typedef for value_type in function_property_map. It should be

typedef typename boost::result_of<Functor(Arg)>::type
  value_type; 

to avoid a potentially circular definition.

comment:8 by Szymon Gatner <szymon.gatner@…>, 12 years ago

Still same error, even with both value_type typedefs (in function_property_map and property_traits) hardcoded to int.

I found that last working revision is 63530.

Briefly judging by revision's description, do I miss some const definitions?

comment:9 by Jeremiah Willcock, 12 years ago

Could you please post the entire error message (including the full instantiation stack)?

by Szymon Gatner <szymon.gatner@…>, 12 years ago

Attachment: BuildLog.htm added

comment:10 by Szymon Gatner <szymon.gatner@…>, 12 years ago

VS build log attached

comment:11 by Jeremiah Willcock, 12 years ago

Could you please try this patch:

Index: /u/jewillco/boost-svn/boost/graph/astar_search.hpp
===================================================================
--- /u/jewillco/boost-svn/boost/graph/astar_search.hpp  (revision 65774)
+++ /u/jewillco/boost-svn/boost/graph/astar_search.hpp  (working copy)
@@ -318,11 +318,11 @@
     // otherwise the value type of the weight map.
     typedef
       typename detail::override_const_property_result<
-                 arg_pack_type, tag::weight_map, edge_weight_t, VertexListGraph>::type
+                 arg_pack_type, tag::weight_map, edge_weight_t, const VertexListGraph>::type
       weight_map_type;
     typedef typename boost::property_traits<weight_map_type>::value_type W;
     typedef
-      typename detail::map_maker<VertexListGraph, arg_pack_type, tag::distance_map, W>::map_type
+      typename detail::map_maker<const VertexListGraph, arg_pack_type, tag::distance_map, W>::map_type
       distance_map_type;
     typedef typename boost::property_traits<distance_map_type>::value_type D;
 
@@ -355,7 +355,7 @@
     BOOST_GRAPH_DECLARE_CONVERTED_PARAMETERS(params_type, params)
     typedef
       typename detail::override_const_property_result<
-                 arg_pack_type, tag::weight_map, edge_weight_t, VertexListGraph>::type
+                 arg_pack_type, tag::weight_map, edge_weight_t, const VertexListGraph>::type
                weight_map_type;
     typedef typename boost::property_traits<weight_map_type>::value_type D;
     astar_search_no_init

comment:12 by Szymon Gatner <szymon.gatner@…>, 12 years ago

No luck.

comment:13 by anonymous, 12 years ago

Any other way I could help?

comment:14 by Jeremiah Willcock, 12 years ago

See if this patch works (either with or without the one I sent before):

Index: boost/graph/named_function_params.hpp
===================================================================
--- boost/graph/named_function_params.hpp       (revision 65774)
+++ boost/graph/named_function_params.hpp       (working copy)
@@ -392,8 +392,8 @@

     template <typename ArgType, typename Prop, typename Graph, bool Exists>
     struct override_const_property_t {
-      typedef ArgType result_type;
-      result_type operator()(const Graph&, const typename boost::add_reference<ArgType>::type a) const {return a;}
+      typedef typename boost::remove_const<ArgType>::type result_type;
+      result_type operator()(const Graph&, const ArgType& a) const {return a;}
     };

     template <typename ArgType, typename Prop, typename Graph>

comment:15 by anonymous, 12 years ago

That works even without first patch applied. Thanks.

comment:16 by Jeremiah Willcock, 12 years ago

Resolution: worksformefixed

(In [65836]) Fixed const issue on VC++ 8; fixes #4715

comment:17 by Jeremiah Willcock, 12 years ago

(In [65839]) Merged r65836 (fix for #4715) from trunk; refs #4715

Note: See TracTickets for help on using tickets.