Re: [Boost-users] mpl programming task
or even more clear:
#include <map>
#include <set>
typedef std::map
peter_foelsche writes:
or even more clear:
#include <map> #include <set>
typedef std::map
CInt2IntMap; typedef std::set CIntSet; static CInt2IntMap convert(const CIntSet &_r) { CInt2IntMap s; for (CIntSet::const_iterator p = _r.begin(); p != _r.end(); ++p) s.insert(std::make_pair(*p, s.size())); return s; }
//required headers
#include <cstddef>
#include
{ }; typedef mpl::vector< mpl::size_t<4>, mpl::size_t<8>, mpl::size_t<42>
test_input_sequence;
typedef mpl::map<
mpl::pair
test_expected_result;
BOOST_MPL_ASSERT((
mpl::equal
#include <map> #include <set>
typedef std::map
CInt2IntMap; typedef std::set CIntSet; static CInt2IntMap convert(const CIntSet &_r) { CInt2IntMap s; for (CIntSet::const_iterator p = _r.begin(); p != _r.end(); ++p) s.insert(std::make_pair(*p, s.size())); return s; }
Thanks Adam.
I found my own solution meanwhile.
I tried both, yours and mine.
Very slowly I'm getting used to this programming style (grin).
The compiler error messages are not very helpful.
Kind Regards
Peter
#include
CFirstSet;
template<typename CFirstSet> struct CMyConvert:boost::mpl::accumulate< CFirstSet, boost::mpl::map<>, boost::mpl::lambda< boost::mpl::insert< boost::mpl::_1, boost::mpl::pair< boost::mpl::_2, boost::mpl::sizeboost::mpl::_1 > > >::type
::type { };
template<typename InputSeq>
struct CConvert : boost::mpl::transform<
InputSeq,
boost::mpl::range_c<
long,
0,
boost::mpl::size<InputSeq>::value
>,
boost::mpl::pair
::type { };
typedef boost::mpl::map<
boost::mpl::pair<
boost::mpl::int_<3>,
boost::mpl::integral_c
CMap1;
typedef boost::mpl::map< boost::mpl::pair< boost::mpl::int_<3>, boost::mpl::long_<0> >, boost::mpl::pair< boost::mpl::int_<1>, boost::mpl::long_<1> >
CMap2;
template<typename T>
struct wrap
{
};
struct CPrintType
{ template<typename T>
void operator()(wrap<T>) const
{ std::cout << typeid(T).name() << "\n";
}
};
int main(int , char **)
{
BOOST_MPL_ASSERT((
boost::mpl::equal_to<
boost::mpl::at<
CConvert<CFirstSet>,
boost::mpl::int_<1>
>::type,
boost::mpl::integral_c
participants (2)
-
Adam Merz
-
peter_foelsche@agilent.com