MPL::lambda issue: what am I doing wrong?

I want to express a "type-mapping" scheme. My implementation idea is this:
have the user define an MPL sequence comprised exclusively of std::pair
derivations. He can then instantiate my template class with his sequence as
the argument. My template then derives two MPL sequences, one containing
the "first" types, the other containing the "second" types.
Here is the attempt:
<code>
namespace ls
{
using namespace boost::mpl;
using namespace placeholders;
template <class TypePairSequence>
struct list_splitter
{
template <class STDPAIR>
struct first_type
{
typedef typename STDPAIR::first_type type;
};
template <class STDPAIR>
struct second_type
{
typedef typename STDPAIR::second_type type;
};
typedef
typename
transform
<
TypePairSequence
, first_type<_1>
>
::type
first_types;
typedef
typename
transform
<
TypePairSequence
, second_type<_1>
>::type
second_types;
};
}//end namespace ls
</code>
Here is an attempt to instantiate:
1> typedef boost::mpl::list< std::pair

I want to express a "type-mapping" scheme. My implementation idea is
Brian Simpson wrote: this:
[...]
Brian, I don't have access to gcc 3.2.2 at the moment, but it looks like
they are still not able to handle the class template arity issues
correctly (your example also fails with an internal compiler error on 3.2).
The essence of the issue is that gcc adopts a non-standard extension
under which two class template specializations like these
template< typename T > struct lambda { typedef T type; };
template<
template< typename > class F
, typename T1
>
struct lambda< F<T1> >
{
};
template<
template< typename, typename > class F
, typename T1, typename T2
>
struct lambda< F

"Aleksey Gurtovoy"
That does help. It gets me to the next (apparent) obstacle, which is that I need to define a variant using the types in the derived sequence (the second_types, to be specific). I'm putting together another post for that one. BTW, would it be possible, using mpl::fold, to get Borland5 to do this? I know that it won't support mpl::lambda, and I'd like my code to compile on Borland5 in addition to gcc3.2.2 . I'll be looking into it, but if you can alert me that it's not possible, that would save me time :). I'm sure I'll be asking for more details later, but for now the documentation is coming through for me. Thanks! Brian

Brian Simpson wrote:
Are we talking about 'boost::variant' here? Because the latter accepts MPL-sequence template arguments directly - you just pass a sequence to it, and that's all.
All MPL algorithms that take lambda expressions can also take _metafunction classes_, so if lambda is unavailable/too complicated, you can always write a standalone auxiliary metafunction class that does what you want and just pass it to the algorithm, e.g. struct do_something { template< typename State, typename T > struct apply { // ... typedef ... type; }; }; // ... typedef mpl::fold< seq, do_something >::type result; Just like you would do it in STL without Boost.Lambda :).
I'm sure I'll be asking for more details later, but for now the documentation is coming through for me.
Good! Aleksey

"Aleksey Gurtovoy"
[...] Oops. I got the impression, from the conversations resulting from the review of boost::variant, that that feature was being removed. I'll try it and see what I get. Meanwhile, just before I got your post, I submitted another one, which deals with this same problem applied to boost::tuple. I'll do a little research over the weekend to see if I jumped the gun there, too ;) . --Brian
participants (2)
-
Aleksey Gurtovoy
-
Brian Simpson