Boost logo

Boost Users :

Subject: [Boost-users] Boost Graph Very Strange Behavior
From: Alexander Feldman (alex_at_[hidden])
Date: 2011-08-20 18:17:10


Dear All,

I have upgraded to Boost 1.47.0 and I have spent a day on the following
strange behavior that someone who knows Boost better may explain to me.
Consider the source below. If I uncomment the line:

     //cout << "";

in line 39, then the program starts working, i.e., it outputs:

0x1

If I comment out line 39, then I get

0

There are no memory leaks.

This kind of stuff gives me nightmares.

Thanks for your help and sorry for the longish example.

Thanks,

-- Alex

-----------------------------------------------------------------------
#include <boost/graph/adjacency_list.hpp>

#include <iostream>

using namespace boost;
using namespace std;

typedef adjacency_list<listS,
                        listS,
                        undirectedS,
                        property<vertex_name_t, void *>,
                        property<edge_name_t, void *> > GraphT;

class Graph : public GraphT
{
public:
     Graph();

public:
     typedef graph_traits<GraphT>::vertex_descriptor VertexType;
     typedef graph_traits<GraphT>::edge_descriptor EdgeType;

public:
     ostream &put(ostream &) const;
     void setNetLabel(const EdgeType &, void *);
     void addNet(const VertexType &, const VertexType &, void *);

private:
     property_map<GraphT, edge_name_t>::type net_;
};

Graph::Graph()
{
     net_ = get(edge_name, *this);
}

void Graph::setNetLabel(const EdgeType &edge, void *label)
{
     //cout << "";

     net_[edge] = label;
}

void Graph::addNet(const VertexType &branch1, const VertexType &branch2,
void *label)
{
     EdgeType ei;
     bool inserted;
     tie(ei, inserted) = add_edge(branch1, branch2, *this);
     if (inserted) {
         setNetLabel(ei, label);
     }
}

ostream &Graph::put(ostream &out) const
{
     graph_traits<GraphT>::edge_iterator ei, ei_end;
     for (tie(ei, ei_end) = edges(*this); ei != ei_end; ei++) {
         out << net_[*ei] << endl;
     }

     return out;
}

int main(int argc, char **argv)
{
     Graph graph;

     Graph::VertexType v1 = add_vertex(graph);
     Graph::VertexType v2 = add_vertex(graph);
     graph.addNet(v1, v2, (void *)1);

     graph.put(cout);

     return EXIT_SUCCESS;
}
-----------------------------------------------------------------------


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net