|
Boost Users : |
From: Brian Simpson (yg-boost-users_at_[hidden])
Date: 2003-07-10 08:50:19
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<long, short>, std::pair<char, double>
> associated_types;
2> typedef ls::list_splitter<associated_types> split_associated_types;
3> typedef split_associated_types::first_types first_types;
4> typedef split_associated_types::second_types second_types;
5> typedef boost::mpl::at_c<first_types, 0>::type first_first_t;
Code lines 1-2 compile fine. When I add line 3, I get the following error:
"no type named `first_type' in `struct boost::mpl::arg<1>'".
If you need more:
<error>
temp.h: In instantiation of
`ls::list_splitter<associated_types>::first_type<boost::mpl::arg<1> >':
boost/mpl/transform.hpp:41: instantiated from
`boost::mpl::apply1<ls::list_splitter<associated_types>::first_type<boost::m
pl::arg<1> >, std::pair<char, double> >'
boost/mpl/transform.hpp:41: instantiated from
`boost::mpl::aux::transform_op<ls::list_splitter<associated_types>::first_ty
pe<boost::mpl::arg<1> > >::apply<boost::mpl::null_node, std::pair<char,
double> >'
boost/mpl/aux_/preprocessed/gcc/fold_backward_impl.hpp:74: instantiated
from `boost::mpl::aux::fold_backward_impl<2,
boost::mpl::list_iterator<boost::mpl::list2<std::pair<long int, short int>,
std::pair<char, double> > >,
boost::mpl::list_iterator<boost::mpl::null_node>, boost::mpl::null_node,
boost::mpl::protect<boost::mpl::aux::transform_op<ls::list_splitter<associat
ed_types>::first_type<boost::mpl::arg<1> > > >, boost::mpl::arg<1> >'
boost/mpl/fold_backward.hpp:45: instantiated from
`boost::mpl::fold_backward<associated_types, boost::mpl::null_node,
boost::mpl::protect<boost::mpl::aux::transform_op<ls::list_splitter<associat
ed_types>::first_type<boost::mpl::arg<1> > > >, boost::mpl::arg<1> >'
boost/mpl/transform.hpp:64: instantiated from
`boost::mpl::algo_::transform<associated_types,
ls::list_splitter<associated_types>::first_type<boost::mpl::arg<1> > >'
temp.h:35: instantiated from `ls::list_splitter<associated_types>'
temp.h:53: instantiated from here
temp.h:19: no type named `first_type' in `struct boost::mpl::arg<1>'
</error>
I'm sure I'm overlooking something simple. Could someone point me in the
right direction?
I'm using gcc3.2.2 on Solaris 9.
TIA,
Brian
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net