Boost logo

Boost Users :

From: David Abrahams (dave_at_[hidden])
Date: 2008-06-22 21:24:32


Ákos Maróy wrote:
> Robert Ramey wrote:
>> Note that the serialization library uses the transform iterator
>> in "real world" code. And there are test of the iterators
>> used by the library which might serve as examples on how
>> to user them.
>
> hm, I did a search within /usr/include/boost/serialization, and did not
> find any references to transform_iterator.
>
> anyway, if there would be a complete example somewhere, I'd be extremely
> greatful... the example on the transform_iterator documentation page is
> partial, for example, it does not define a complet example. when I try
> to use the sample given here:
> http://lists.boost.org/boost-users/2007/11/32410.php , I get the
> following error:
>
> no type named ‘result_type’ in 'struct get_pair_value'
>
> I complete working example would really be appreciated.

As described in
http://www.boost.org/doc/libs/1_35_0/libs/iterator/doc/transform_iterator.html#transform-iterator-requirements,
your UnaryFunction needs to support result_of

  // untested

  #include "boost/type_traits/remove_reference.hpp"
  #include "boost/type_traits/remove_const.hpp"
  struct get_pair_value
  {
      template < class P >
      struct result
      {
          typedef typename boost::remove_const<
              typename boost::remove_reference<P>::type
>::type::second_type type;
      };

      template< typename K, typename V >
      V operator()( std::pair< K, V > const& pr )
      { return pr.second; }
  };

Sorry that's so complicated; result_of ought to be easier to use than it is.

-- 
Dave Abrahams
BoostPro Computing
http://www.boostpro.com

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