|
Boost Users : |
Subject: [Boost-users] mpl/fusion: metafunction to 'rangify'
From: Hicham Mouline (hicham_at_[hidden])
Date: 2009-12-22 16:12:33
I am making small progress in my attempt to generate a new mpl sequence that
I will use to read from a stream.
The following code fails to compile:
#include <boost/tuple/tuple.hpp>
#include <boost/mpl/vector_c.hpp>
#include <boost/mpl/transform.hpp>
#include <boost/fusion/adapted/struct/adapt_struct.hpp>
#include <boost/fusion/include/adapt_struct.hpp>
#include <boost/fusion/mpl.hpp> // makes params a MPL
sequence
#include <boost/fusion/support/is_sequence.hpp>
#include <boost/fusion/include/is_sequence.hpp>
struct params {
double d1;
double d2;
double d3;
unsigned int i4;
unsigned int i5;
unsigned int i6;
unsigned int i7;
};
BOOST_FUSION_ADAPT_STRUCT(
params,
(double, d1)
(double, d2)
(double, d3)
(unsigned int, i4)
(unsigned int, i5)
(unsigned int, i6)
(unsigned int, i7)
)
BOOST_MPL_ASSERT(( boost::fusion::traits::is_sequence<params> )); // passes
template <typename T1>
struct rangify {
typedef boost::tuple<T1, T1, T1> type; /// min max incr
};
template <typename T>
struct fixed_or_range {
typedef struct {
union {
T fixed;
typename rangify<T>::type range;
};
bool is_fixed;
}
type;
};
typedef boost::mpl::transform< params, fixed_or_range<boost::mpl::_> >::type
params_fixed_or_range;
I understand that after the macro BOOST_FUSION_ADAPT_STRUCT , params is a
fusion sequence.
Including <boost/fusion/mpl.hpp> made params a MPL sequence, and therefore I
can call boost::mpl::transform<> on it.
The compilation error is
c:\program files (x86)\boost_1_41_0\boost\mpl\clear.hpp(30) : error C2903:
'apply' : symbol is neither a class template nor a function template
1> c:\program files (x86)\boost_1_41_0\boost\mpl\transform.hpp(113) :
see reference to class template instantiation 'boost::mpl::clear<Sequence>'
being compiled
1> with
1> [
1> Sequence=params
1> ]
1> c:\program files (x86)\boost_1_41_0\boost\mpl\eval_if.hpp(41) :
see reference to class template instantiation
'boost::mpl::transform1<P1,P2,P3>' being compiled
1> with
1> [
1> P1=params,
1> P2=fixed_or_range<boost::mpl::_1>,
1> P3=boost::mpl::na
1> ]
1> c:\program files (x86)\boost_1_41_0\boost\mpl\transform.hpp(138) :
see reference to class template instantiation 'boost::mpl::eval_if<C,F1,F2>'
being compiled
1> with
1> [
1>
C=boost::mpl::or_<boost::mpl::is_na<boost::mpl::na>,boost::mpl::is_lambda_ex
pression<fixed_or_range<boost::mpl::_1>>,boost::mpl::not_<boost::mpl::is_seq
uence<fixed_or_range<boost::mpl::_1>>>>,
1>
F1=boost::mpl::transform1<params,fixed_or_range<boost::mpl::_1>,boost::mpl::
na>,
1>
F2=boost::mpl::transform2<params,fixed_or_range<boost::mpl::_1>,boost::mpl::
na,boost::mpl::na>
1> ]
1> c:\users\hich\documents\visual studio
2008\projects\test\test1\main.cpp(51) : see reference to class template
instantiation 'boost::mpl::transform<Seq1,Seq2OrOperation>' being compiled
1> with
1> [
1> Seq1=params,
1> Seq2OrOperation=fixed_or_range<boost::mpl::_1>
1> ]
Regards,
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