|
Boost : |
From: Joel de Guzman (joel_at_[hidden])
Date: 2003-10-23 18:44:30
David B. Held <dheld_at_[hidden]> wrote:
> "Joel de Guzman" <joel_at_[hidden]> wrote in message
> news:02b501c3994b$a8625780$64646464_at_godzilla...
>> [...]
>> The Fusion lib (in the sandbox) hopefully to replace the old tuple
>> lib can do that easily (example):
>>
>> typedef boost::mpl::list<int, double, X, int> mpl_list1;
>> type_sequence<mpl_list1> view;
>> std::cout << generate(view) << std::endl;
>>
>> generate(view) creates a tuple from the view.
>
> This looks promising, but could you briefly explain what a view
> is?
I'm writing some docs now. I posted some info regarding Fusion here:
http://lists.boost.org/MailArchives/boost/msg53297.php
> And can I just create my tuple directly from the sequence?
> Like so:
>
> template <typename T>
> struct foo
> {
> typedef typename as_sequence<T>::type my_types;
>
> foo(void) : my_tuple(generate(type_sequence<my_types>())) { }
>
> tuple<???> my_tuple;
> };
Yes. The usage will be something like:
template <typename T>
struct foo
{
typedef typename as_sequence<T>::type my_types;
typedef type_sequence<my_types> type_sequence;
foo(void) : my_tuple(generate(type_sequence())) { }
typename result_of_generate<type_sequence>::type my_tuple;
};
I'm still experimenting on the easiest syntax. For example, I think
it is possible to directly regard MPL sequences as Fusion views.
Thus:
template <typename T>
struct foo
{
typedef typename as_sequence<T>::type my_types;
foo(void) : my_tuple(generate(my_types())) { }
typename result_of_generate<my_types>::type my_tuple;
};
> Remember that I'm trying to get to here:
>
> get<3>(foo().my_tuple);
>
> That is, I want to be able to access the individual tuple elements
> at run-time. So if there's a better way to do that in fusion, then
> I'm all ears.
That and a lot more! Fusion is an entire MPL library for tuples!
If you know MPL, you'll love Fusion :-)
Cheers,
-- Joel de Guzman http://www.boost-consulting.com http://spirit.sf.net
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk