Boost logo

Boost :

From: Jeremy Siek (jsiek_at_[hidden])
Date: 2001-04-20 13:34:46


Hi,

I'm not sure why things were working on 1.18.0. It looks to me
like there are several errors.

  - typically you don't need to directly use property_kind
    and property_num. They are helpers used inside the property maps.
  - the argument to get() should be the same property tag
    that you use in property_map, in this case Property_T.
  - If you want to create a reference to an object from a property
     map, you need to access the object using the LvaluePropertyMap
     interface, i.e., operator[]. The get() property map function
     returns the object by-value, creating a temporary.

Here's the corrected code:

template <class Property_T, class EdgeIter, class Graph>
void links_to(EdgeIter first,
              EdgeIter last,
              const Graph& G,
              std::ostream& p_out) {

  typedef typename
    boost::property_map<Graph, Property_T>::const_type ValueMap;
  typedef typename
    boost::property_traits<ValueMap>::value_type ValueType;

  ValueMap name = boost::get(Property_T(), G);

  while (first != last) {
    const ValueType& src_name = name[source(*first,G)];
    const ValueType& trg_name = name[target(*first,G)];
    p_out << src_name << " ----> "
          << trg_name << endl;
      ++first;
    }
  }
}

Hope this helps!

Cheers,
Jeremy

On Fri, 20 Apr 2001, Joel Young wrote:
jdy>
jdy> Does anyone see what is wrong with this?
jdy>
jdy> template <class Property_T, class EdgeIter, class Graph>
jdy> void links_to(EdgeIter first,
jdy> EdgeIter last,
jdy> const Graph& G,
jdy> std::ostream& p_out) {
jdy>
jdy> typedef typename
jdy> boost::property_map<Graph, Property_T>::const_type ValueMap;
jdy> typedef typename
jdy> boost::property_traits<ValueMap>::value_type ValueType;
jdy>
jdy> typedef typename
jdy> boost::property_kind<Property_T>::type property_tag;
jdy>
jdy> // Access the property accessor type for this graph
jdy> const ValueMap& name = boost::get(property_tag,G);
jdy>
jdy> // This used to work in 1.18.0
jdy> // const ValueMap& name(
jdy> // boost::get(
jdy> // (Property_T)boost::property_num<Property_T>::value,G));
jdy>
jdy> while (first != last) {
jdy> const ValueType& src_name = boost::get(name, source(*first, G));
jdy> const ValueType& trg_name = boost::get(name, target(*first, G));
jdy> p_out << src_name << " ----> "
jdy> << trg_name << endl;
jdy> ++first;
jdy> }
jdy> }
jdy>
jdy>
jdy> It gives:
jdy> file.h: In function `void links_to(EdgeIter, EdgeIter, const Graph&,
jdy> ostream&)':
jdy> file.h:22: parse error before `,' token
jdy> file.h:22: declaration of `G' shadows a parameter
jdy>
jdy> with gcc 3.1 (20010417) and gcc 2.95.2
jdy>
jdy>
jdy> Joel
jdy> jdy_at_[hidden]
jdy>
jdy> To unsubscribe, send email to: <mailto:boost-unsubscribe_at_[hidden]>
jdy>
jdy>
jdy> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
jdy>
jdy>
jdy>

----------------------------------------------------------------------
 Jeremy Siek www: http://www.lsc.nd.edu/~jsiek/
 Ph.D. Candidate email: jsiek_at_[hidden]
 Univ. of Notre Dame work phone: (219) 631-3906
----------------------------------------------------------------------


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk