Boost logo

Boost Users :

From: TC MA (maottawa3_at_[hidden])
Date: 2004-11-24 11:21:10


Still has a compile problem.
interior_property_map.cpp is now:

struct vertexStruct {
  string name;
};

template <class EdgeIter, class Graph>
void who_owes_who(EdgeIter first, EdgeIter last, const
Graph& G)
{
  // Access the propety acessor type for this graph
  typedef typename property_map<Graph,
&vertexStruct::name>::const_type NamePA;
// typedef typename property_map<Graph,
vertexStruct::name>::const_type NamePA;

  NamePA name = get(&vertexStruct, G);

  typedef typename
boost::property_traits<NamePA>::value_type NameType;

  NameType src_name, targ_name;

  while (first != last) {
    src_name = G[source(*first, G)].name;
    targ_name = G[target(*first, G)].name;
    cout << src_name << " owes "
         << targ_name << " some money" << endl;
    ++first;
  }
}

int
main()
{
  {
    // Create the graph, and specify that we will use
std::string to
    // store the first name's.
    typedef adjacency_list<vecS, vecS, directedS,
vertexStruct> MyGraphType;
    
    typedef pair<int,int> Pair;
    Pair edge_array[11] = { Pair(0,1), Pair(0,2),
Pair(0,3), Pair(0,4),
                            Pair(2,0), Pair(3,0),
Pair(2,4), Pair(3,1),
                            Pair(3,4), Pair(4,0),
Pair(4,1) };
    
    MyGraphType G(5);
    for (int i=0; i<11; ++i)
      add_edge(edge_array[i].first,
edge_array[i].second, G);
    MyGraphType::vertex_descriptor v =
*vertices(G).first;
    G[v].name = "TingChong";
    ++v;
    G[v].name = "Carmen";
  
    who_owes_who(edges(G).first, edges(G).second, G);
  }

  cout << endl;

  return 0;
}

Compiler output is:
gcc-C++-action
/home/tcma/cpp/boosttcma/libs/graph/interior_property_map.test/gcc/debug/inlining-on/interior_property_map.o
/home/tcma/cpp/boosttcma/libs/graph/interior_property_map.cpp:
In function `void who_owes_who(EdgeIter, EdgeIter,
const Graph&)':
/home/tcma/cpp/boosttcma/libs/graph/interior_property_map.cpp:59:
error: type/value mismatch at argument 2 in template
parameter list for `template<class Graph, class
Property> struct boost::property_map'
/home/tcma/cpp/boosttcma/libs/graph/interior_property_map.cpp:59:
error: expected a type, got `& vertexStruct::name'
/home/tcma/cpp/boosttcma/libs/graph/interior_property_map.cpp:59:
error: `const_type' does not name a type
/home/tcma/cpp/boosttcma/libs/graph/interior_property_map.cpp:64:
error: `NamePA' undeclared (first use this function)
/home/tcma/cpp/boosttcma/libs/graph/interior_property_map.cpp:64:
error: (Each undeclared identifier is reported only
once for each function it appears in.)
/home/tcma/cpp/boosttcma/libs/graph/interior_property_map.cpp:64:
error: expected `;' before "name"
/home/tcma/cpp/boosttcma/libs/graph/interior_property_map.cpp:66:
error: template argument 1 is invalid
/home/tcma/cpp/boosttcma/libs/graph/interior_property_map.cpp:66:
error: `value_type' does not name a type
/home/tcma/cpp/boosttcma/libs/graph/interior_property_map.cpp:68:
error: `NameType' undeclared (first use this function)
/home/tcma/cpp/boosttcma/libs/graph/interior_property_map.cpp:68:
error: expected `;' before "src_name"
/home/tcma/cpp/boosttcma/libs/graph/interior_property_map.cpp:71:
error: `src_name' undeclared (first use this function)
/home/tcma/cpp/boosttcma/libs/graph/interior_property_map.cpp:72:
error: `targ_name' undeclared (first use this
function)

    set -e
    "g++" -c -Wall -ftemplate-depth-255 -g -O0
-Wno-inline
-I"../../../bin/boost/libs/graph/example" -I
"/home/tcma/cpp/boost_1_32_0" -o
"/home/tcma/cpp/boosttcma/libs/graph/interior_property_map.test/gcc/debug/inlining-on/interior_property_map.o"

"/home/tcma/cpp/boosttcma/libs/graph/interior_property_map.cpp"
    "/usr/bin/objcopy" --set-section-flags
.debug_str=contents,debug
"/home/tcma/cpp/boosttcma/libs/graph/interior_property_map.test/gcc/debug/inlining-on/interior_property_map.o"

...failed gcc-C++-action
/home/tcma/cpp/boosttcma/libs/graph/interior_property_map.test/gcc/debug/inlining-on/interior_property_map.o...
...skipped
</home/tcma/cpp/boosttcma/libs/graph/interior_property_map.test/gcc/debug/inlining-on>/home/tcma/cpp/boosttcma/libs/graph/interior_property_map
for lack of
</home/tcma/cpp/boosttcma/libs/graph/interior_property_map.test/gcc/debug/inlining-on>interior_property_map.o...
...skipped
</home/tcma/cpp/boosttcma/libs/graph/interior_property_map.test/gcc/debug/inlining-on>/home/tcma/cpp/boosttcma/libs/graph/interior_property_map.run
for lack of
</home/tcma/cpp/boosttcma/libs/graph/interior_property_map.test/gcc/debug/inlining-on>/home/tcma/cpp/boosttcma/libs/graph/interior_property_map...
...failed updating 1 target...
...skipped 3 targets...

> Date: Wed, 24 Nov 2004 00:07:08 -0500
> From: Doug Gregor <dgregor_at_[hidden]>
> Subject: Re: [Boost-users] newbie: Graph library -
bundled properties
> revisited
> To: boost-users_at_[hidden]
> Message-ID:
<B11939FE-3DD6-11D9-9E73-000D932B7224_at_[hidden]>
> Content-Type: text/plain; charset=US-ASCII;
format=flowed
>
> On Nov 23, 2004, at 10:56 PM, TC MA wrote:
> > // create a tag for our new property
> >
> > enum vertex_first_name_t { vertex_first_name };
> > namespace boost {
> > BOOST_INSTALL_PROPERTY(vertex, first_name);
> > }
>
> You won't actually need the part above this any
more.
>
> > struct vertexStruct {
> > string name;
> > };
> >
> > template <class EdgeIter, class Graph>
> > void who_owes_who(EdgeIter first, EdgeIter last,
const
> > Graph& G)
> > {
> > // Access the propety acessor type for this
graph
> > typedef typename property_map<Graph,
> > vertexStruct::name>::const_type NamePA;
>
> The compiler is actually giving a somewhat useful
message here: add an
> '&' before the vertexStruct::name to form a
pointer-to-member.
>
> > NamePA name = get(vertex_first_name, G);
>
> Here again, you'll want to use a pointer-to-member,
like this:
>
> NamePA name = get(&vertexStruct, G);
>
> > typedef typename
> > boost::property_traits<NamePA>::value_type
NameType;
> >
> > NameType src_name, targ_name;
> >
> > while (first != last) {
> > src_name = boost::get(name, source(*first,G));
> > targ_name = boost::get(name,
target(*first,G));
>
> Now you can use the simpler:
>
> src_name = G[source(*first, G)].name;
> targ_name = G[target(*first, G)].name;
>
> Once you've replaced the original get calls with
these lines, you can
> remove the definition of the "name" variable as
well.
>
> Doug

=====
TingChong Ma

______________________________________________________________________
Post your free ad now! http://personals.yahoo.ca


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