Opened 17 years ago

Closed 17 years ago

#512 closed Bugs (Invalid)

predicates without default constructor fail to compile (2)

Reported by: nobody Owned by: Douglas Gregor
Milestone: Component: graph
Version: None Severity:
Keywords: Cc:

Description

The first time I submitted I forgot to check the box for 
uploading the zip archive...

I want to draw your attention to a possible flaw in the 
implementation of the write_graphviz method from the 
Boost Graph Library.

The current implementation uses the assignment 
operator for the vertex and edge iterators. This is natural, 
but some examples fail to compile with
this version. The problem comes from the predicates 
witch don't have default constructors. 

When trying to assign a vertex iterator of a graph 
filtered with such a predicate, the compiler issues an 
error:

C2512:'positive_edge_weight_pred<MyEdgeWeightMap>'
: no appropriate default constructor available
with
[
MyEdgeWeightMap=EdgeWeightMapT
]

If a small modification in the write_graphviz 
implementation is made (using copy constructors 
instead of assignement operators), the example 
compiles and runs sucesfully. I am using the Microsoft 
Visual C++ 7.1 compiler.

In conclusion, I think that this modification should be 
made, as it grows the flexibility of the library and doesn't 
add any overhead.

I have attached the example (main.cpp) and the patch 
for graphviz.hpp (graphviz.hpp.patch).

My e-mail adress is pdumitrache@bphx.ro

Change History (1)

comment:1 by Douglas Gregor, 17 years ago

Status: assignedclosed
Logged In: YES 
user_id=249098

This is not a bug in write_graphviz. The predicate (in this case, 
positive_edge_weight_pred) must be both Default Constructible and 
Assignable, according to the requirements listed in the filtered_graph 
documentation. However, it does not meet these requirements. The bug 
(unfortunately) shows up in a call to write_graphviz.

To correct the example, store the weight map by value or pointer in the 
predicate, not by reference.
Note: See TracTickets for help on using tickets.