Modify

Ticket #4715 (closed Bugs: fixed)

Opened 4 years ago

Last modified 4 years ago

custom property_map no longer works for astar_search

Reported by: Szymon Gatner <szymon.gatner@…> Owned by: jewillco
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

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

Change History

comment:1 Changed 4 years ago by Szymon Gatner <szymon.gatner@…>

  • Owner set to asutton
  • Component changed from None to graph

comment:2 Changed 4 years ago by jewillco

  • Owner changed from asutton to jewillco

comment:3 Changed 4 years ago by jewillco

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

Changed 4 years ago by Szymon Gatner <szymon.gatner@…>

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

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

comment:5 Changed 4 years ago by jewillco

  • Status changed from new to closed
  • Resolution set to worksforme

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 4 years ago by jewillco (previous) (diff)

comment:6 Changed 4 years ago by Szymon Gatner <szymon.gatner@…>

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 Changed 4 years ago by jewillco

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 Changed 4 years ago by Szymon Gatner <szymon.gatner@…>

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 Changed 4 years ago by jewillco

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

Changed 4 years ago by Szymon Gatner <szymon.gatner@…>

comment:10 Changed 4 years ago by Szymon Gatner <szymon.gatner@…>

VS build log attached

comment:11 Changed 4 years ago by jewillco

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 Changed 4 years ago by Szymon Gatner <szymon.gatner@…>

No luck.

comment:13 Changed 4 years ago by anonymous

Any other way I could help?

comment:14 Changed 4 years ago by jewillco

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 Changed 4 years ago by anonymous

That works even without first patch applied. Thanks.

comment:16 Changed 4 years ago by jewillco

  • Resolution changed from worksforme to fixed

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

comment:17 Changed 4 years ago by jewillco

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

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.