Boost logo

Boost :

From: Steven Watanabe (steven_at_[hidden])
Date: 2006-11-16 00:05:17


AMDG

MuTPu4 wrote:

> While using standart algorithm wrappers (::boost::lambda::ll) I find out
> that
> there is no way to call non-constant versions of begin/end without defining
> new
> helper functors in the user code. In other words, algorithms like ll::sort
> as-
> is are unusable.
> I think it would be nice to add a pair of non-const helper functors, i.e.
> call_mutable_begin and call_mutable_end to the library.
>

Perhaps deducing the iterator type from the constness of the parameter
would be even
better?

template<class T>
struct get_iterator {
    typedef typename T::iterator type;
};
template<class T>
struct get_const_iterator {
    typedef typename T::const_iterator type;
};
struct call_begin {
    template<class Args>
    struct sig {
        typedef typename boost::tuples::element<1, Args>::type arg_type;
        typedef typename boost::mpl::eval_if<boost::is_const<arg_type>,
            get_const_iterator<arg_type>,
            get_iterator<arg_type>
>::type type;
    };
    template<class T>
    typename T::iterator operator()(T& t) const {
        return(t.begin());
    }
    template<class T>
    typename T::const_iterator operator()(const T& t) const {
        return(t.begin());
    }
};

In Christ,
Steven Watanabe


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