Boost logo

Boost Users :

From: Angus Leeming (angus.leeming_at_[hidden])
Date: 2004-07-01 06:20:26

Consider a container such as
        std::vector<std::pair<int, std::string> > my_container;

I want to be able to iterate over the ints of this container so, following
the tutorial to the iterator_adaptor docs, came up with

template <typename BaseIterator>
class first_iter
        : public boost::iterator_adaptor<
                typename BaseIterator::value_type::first_type &
        // snip body

This works fine so long as BaseIterator::value_type is not const, but falls
over when it is because I've defined the 'super_t::reference' type to be

I guess that I need a piece of metafunction magic, but my naive
implementation fails

        typename boost::mpl::apply_if<
                  boost::is_const<typename BaseIterator::value_type>
                , typename BaseIterator::value_type::first_type const &
                , typename BaseIterator::value_type::first_type &

trial.C:38: error: no type named `type' in `struct
        boost::is_const<std::pair<int, std::string> >,
        const int&,

I must admit I'm a bit baffled. There plainly is a 'type' in the apply_if
class template. Any pointers? I attach the code as I have it.

While I'm at it, is there not something in the MPL that will return the
appropriate const-qualified reference for me? None of the header file
names in boost/mpl jump out and grab me, but I may well be looking in the
wrong place.


Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at