|
Boost : |
From: Aleksey Gurtovoy (agurtovoy_at_[hidden])
Date: 2002-07-25 04:49:53
Jaap Suter wrote:
> just when I thought I've seen it all in C++, the MPL pops up.
> Typelists where cool and all, but the way you have created
> an STL-ish MPL that seperates algorithm and container is
> stunning to say the least.
Thank you!
> Is the current MPL release (July 17th) designed to work with
> MSVC 6.0 Service Pack 5?
Yes. You can even use lambda expression, although (obviously) there are some
limitation.
> Does the code-generation facilities of MPL allow something
> like the following (pseudocode):
>
> template< typename t_TypeList >
> class Tree
> {
> // Constructor;
> Tree( t_TypeList[ 0 ]* a_Child_0,
> t_TypeList[ 0 ]* a_Child_1,
> t_TypeList[ 0 ]* a_Child_2,
> ......
> t_TypeList[ 0 ]* a_Child_n );
>
> // Attributes;
> t_TypeList[ 0 ]* m_Child_0;
> t_TypeList[ 1 ]* m_Child_1;
> t_TypeList[ 2 ]* m_Child_2;
> ........
> t_TypeList[ n ]* m_Child_n;
> }
Constructor is a problem (preprocessor can help there, though), members -
easily:
template< typename Base, typename Iterator >
struct tree_node
: Base
{
typedef typename Iterator::type T;
typedef typename Iterator::pos pos;
typedef tree_node type; // makes 'tree_node' a metafunction
using Base::node;
T& node(mpl::int_c<pos::value>);
T m_node;
};
struct empty_tree
{
void node();
};
template< typename Types >
struct tree
: mpl::iter_fold<
Types
, empty_tree
, tree_node<_,_>
>::type
{
};
int main()
{
tree< mpl::vector<int,long,bool> > t;
t.node(mpl::int_c<1>()) = -1l;
assert(t.node(mpl::int_c<1>()) == -1l);
}
Aleksey
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk