Opened 15 years ago

Closed 15 years ago

Last modified 15 years ago

#369 closed request (fixed)

create unweighted iterator from weighted iterator

Reported by: Peter Owned by: Peter
Priority: major Milestone: yat 0.5
Component: utility Version: trunk
Keywords: Cc:

Description (last modified by Peter)

needed for ticket:366

related to ticket:368 and ticket:391

A weighted iterator points to a pair of data and weight. It would be useful to be able to create an unweighted iterator that points to either the data or weight. A possible interface could be to have a DataIterator and WeightIterator that are created from an iterator. Using the traits in iterator_traits would allow this to also work for an unweighted iterator (in case that is wanted).

Change History (9)

comment:1 Changed 15 years ago by Peter

It would be good if this adaptor could also be used to iterator over data in a map.

For example:

map<string, int> months;
months["Jan"]=1;
months["Feb"]=6;
...
std::vector<int> vec(map.size());
copy(MyIter(months.begin()), MyIter(months.end()), vec.begin());

So we need a Adaptor that can be tailored to return different things for operator-> and *. The tailor suitable for doing the job, is likely a Policyclass. Then we can typedefs such as

typedef Adaptor<Policy1> Iterator1;
typedef Adaptor<Policy2> Iterator2;
et cetera

comment:2 Changed 15 years ago by Peter

Description: modified (diff)

needed for ticket:366

comment:3 Changed 15 years ago by Peter

Owner: changed from Jari Häkkinen to Peter
Status: newassigned

comment:4 Changed 15 years ago by Peter

(In [1363]) Working #369

comment:5 Changed 15 years ago by Peter

Description: modified (diff)

ticket:391 was marked as related

comment:6 Changed 15 years ago by Peter

Resolution: fixed
Status: assignedclosed

fixed in [1375] [1376] & [1377]

comment:7 in reply to:  1 Changed 15 years ago by Peter

Replying to peter:

It would be good if this adaptor could also be used to iterator over data in a map.

For example:

map<string, int> months;
months["Jan"]=1;
months["Feb"]=6;
...
std::vector<int> vec(map.size());
copy(MyIter(months.begin()), MyIter(months.end()), vec.begin());

For this purpose one could use boost::transform_iterator with a unary function returning second(), see http://www.boost.org/doc/libs/1_33_1/libs/iterator/doc/transform_iterator.html In other words, no reason to add this functionality in yat.

comment:8 Changed 15 years ago by Peter

(In [1399]) refs #369 added a function to create a boost::transform_iterator that was mentioned in ticket:369 - should probably add the corresponding for pair::second too.

comment:9 Changed 15 years ago by Peter

(In [1403]) function pair_second_iteratr that takes an iterator with value std::pair and transform it into an iterator of type pair::second_type. refs #369

Note: See TracTickets for help on using tickets.