|
Boost Users : |
Subject: Re: [Boost-users] mpl and mpl::vector_c and or_ and transform
From: Adam Merz (adammerz_at_[hidden])
Date: 2008-09-26 22:53:28
peter_foelsche wrote:
> This code does not compile.
> I'm using Visual C++.
> Any help would be appreciated.
I'm still quite unclear as to what you're trying to accomplish, but the
following compiles:
#include <utility>
#include <boost/mpl/placeholders.hpp>
#include <boost/mpl/back.hpp>
#include <boost/mpl/for_each.hpp>
#include <boost/mpl/front.hpp>
#include <boost/mpl/or.hpp>
#include <boost/mpl/transform.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/zip_view.hpp>
#include <boost/noncopyable.hpp>
namespace mpl = boost::mpl;
template<typename T>
struct wrap { };
template<typename CDB>
struct CDer
{ };
template<typename CDB, typename CDB1>
struct CMyOperation : private boost::noncopyable
{
typedef CDer
<
typename mpl::transform<CDB, CDB1, mpl::or_<mpl::_1, mpl::_2> >::type
> CDerOr;
CMyOperation(CDer<CDB> const& r0, CDer<CDB1> const& r1, CDerOr& rT)
: m_r0(r0),
m_r1(r1),
m_rT(rT),
m_iPos(0)
{ }
void operator ()(std::pair<bool, bool> const&)
{
++m_iPos;
}
private:
CDer<CDB> const& m_r0;
CDer<CDB1> const& m_r1;
CDerOr& m_rT;
unsigned m_iPos;
};
template<typename CDB, typename CDB1>
struct CCreatePair
{
CCreatePair(CMyOperation<CDB, CDB1>& op) : m_sOp(&op) { }
typedef void result_type;
template<typename T>
void operator ()(wrap<T>) const
{
typedef typename mpl::front<T>::type first;
typedef typename mpl::back<T>::type second;
(*m_sOp)(std::make_pair(first::value, second::value));
}
private:
CMyOperation<CDB, CDB1>* m_sOp;
};
template<typename CDB, typename CDB1>
typename CMyOperation<CDB, CDB1>::CDerOr myOperation(CDer<CDB> const& _r0,
CDer<CDB1> const& _r1)
{
typedef mpl::zip_view<mpl::vector<CDB, CDB1> > CMerged;
typename CMyOperation<CDB, CDB1>::CDerOr sRet;
CMyOperation<CDB, CDB1> sOp(_r0, _r1, sRet);
CCreatePair<CDB, CDB1> createPair(sOp);
mpl::for_each<CMerged, wrap<mpl::_1> >(createPair);
return sRet;
}
int main()
{
CDer<mpl::vector<mpl::true_, mpl::true_> > sDer0;
CDer<mpl::vector<mpl::false_, mpl::true_> > sDer1;
myOperation(sDer0, sDer1);
return 0;
}
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