Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2004-10-10 06:31:55


Terje Slettebø <tslettebo_at_[hidden]> writes:

> template<class T>
> struct to_sequence
> {
> public:
> to_sequence(T &s) : sequence(s) {}
>
> template<class Element>
> void operator()(Element e)
> {
> sequence.push_back(e.value);
> }
>
> private:
> T &sequence;
> };
>
> ...
>
> // int_vector r_list = to_runtime<c_list>();
>
> int_vector r_list;
>
> boost::mpl::for_each<c_list>(to_sequence<int_vector>(r_list));

Better yet:

    int_vector r_list;
    boost::mpl::for_each<c_list>(std::back_inserter(r_list));

Enjoy ;-)

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

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