|
Boost : |
From: Terje Slettebø (tslettebo_at_[hidden])
Date: 2004-10-09 21:28:37
>From: "Jaap Suter" <boost_at_[hidden]>
> what is the easiest way to convert an mpl::sequence to an std::sequence?
>
> I'm using such conversions a lot when unit-testing meta-code. I just wrote
> two versions of algorithms, a compile-time and the runtime one, and then
> compare their outputs.
>
> I recall hearing something about mpl::for_each having defined an operator
()
> for runtime purposes, but the details don't seem to be documented
anywhere.
Yeah, I guess Aleksey and Dave have been busy with the forthcoming MPL book,
but as I understand from list postings, the MPL docs will be updated in
Boost 1.32, and mpl::for_each is one of the more useful components. Since
it's not documented, I learned how it works from Aleksey. The following
works with your code:
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));
Regards,
Terje
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk