Topic: add std::map iterators iterator_key_type and


Author: dave@boost-consulting.com (David Abrahams)
Date: Tue, 6 Jul 2004 22:05:42 +0000 (UTC)
Raw View
vadima@waterint.com (VAdim) writes:

>> Suggestion:
>>
>>   use boost::transform_iterator with select1st or select2nd.
>
> That really solves problem, thank You.
> I think accessing 1st and 2nd elements in the std::map::value type is
> to coomon, and desereve special function.
>
> select1st and select2nd are not standard.
>
> And I suggest function:
> template< typename Iterator, typename V>
> boost::make_transform_iterator( Iterator I, V
> Iterator::value_type::*member );
>
> and
>
> template< typename Iterator, typename V>
> boost::make_transform_iterator( Iterator I, V
> (Iterator::value_type::*f)() );
>
> to ease on fly making iterators

What's V?

I don't think it's worth adding overloads when we have boost::bind
and boost::mem_fn.  Either of these is just:

  make_transform_iterator(some_iterator, boost::mem_fn(&Value::some_member));

--
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: dave@boost-consulting.com (David Abrahams)
Date: Sat, 3 Jul 2004 01:25:22 +0000 (UTC)
Raw View
dietmar_kuehl@yahoo.com (Dietmar Kuehl) writes:

> vadima@waterint.com (VAdim) wrote:
>> Motivation:
>> I wanted to copy mapped values from the map into set, and I did'n find
>> easy way to do this. Similar problem appears when one want to apply
>> some function to the second member of the std::map only.
>>
>> Proposal:
>> Add bidirectional iterators to the std::map iterator_key_type and
>> iterator_mapped_type which will point to the first/second part of the
>> std::map::value_type
>
> I would oppose such a proposal: the general approach to do something like
> this is the separation of iterators into cursors (the positioning part of
> the iterator) and property maps (the property access part of the iterator).
> A sample implementation of algorithms based on this is idea is available at
> <http://www.dietmar-kuehl.de/cool/cool-20030106.tar.gz>. In addition to
> solving the problem you mention, this solves a bunch of other problems, too.

You should really write something up that describes the problems
solved by cursors/property-maps that aren't also solved by iterator
adaptors.  IIRC there are very few such cases and people need a way
to evaluate whether they are worth the complication induced by
decoupling positioning and access.

--
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]





Author: dave@boost-consulting.com (David Abrahams)
Date: Thu, 1 Jul 2004 04:31:17 +0000 (UTC)
Raw View
vadima@waterint.com (VAdim) writes:

> Motivation:
> I wanted to copy mapped values from the map into set, and I did'n find
> easy way to do this. Similar problem appears when one want to apply
> some function to the second member of the std::map only.
>
> Proposal:
> Add bidirectional iterators to the std::map iterator_key_type and
> iterator_mapped_type which will point to the first/second part of the
> std::map::value_type
>
> Example of implementation:

Suggestion:

  use boost::transform_iterator with select1st or select2nd.

  http://www.boost.org/libs/iterator

Cheers,
--
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]