|
Boost : |
From: Sergey Pisarchik (Sergey_pisarchiK_at_[hidden])
Date: 2005-01-10 05:20:36
Hello All,
Problem is:
what the difference between "type" in such cases?
1)
class type{};
and
2)
class type1{};
typedef type1 type;
I think, they are equal. But... look code.
/////////////////////////////////////
//// Begin of code
/////////////////////////////////////
#include <boost\mpl\apply.hpp>
#include <boost\mpl\lambda.hpp>
#include <boost\mpl\placeholders.hpp>
namespace mpl = boost::mpl;
struct CClass{ void Init(int& i){i--;};};
namespace impl
{
template<typename TBase> struct CClass0:public TBase {
public: void Init(int& i){i--; TBase::Init(i);};
};
template<typename TBase> struct CClass1:public TBase {
public: void Init(int& i){i--; TBase::Init(i);}
;};
}
typedef mpl::lambda<impl::CClass0<mpl::_> >::type CClass0;
typedef mpl::lambda<impl::CClass1<mpl::_> >::type CClass1;
template <typename T1, typename T2> struct CMetaFunction1
{
struct type1: public mpl::apply<T1, T2>::type{};
typedef type1 type;
};
template <typename T1, typename T2> struct CMetaFunction2
{
struct type: public mpl::apply<T1, T2>::type{};
};
class CBase
{
CBase(void)
{
{
CMetaFunction1<CClass1, CMetaFunction1<CClass0, CClass>::type >::type g;
int i=5;
g.Init(i);
}
{
CMetaFunction2<CClass1, CMetaFunction2<CClass0, CClass>::type >::type g;
int i=5;
g.Init(i);
}
}
};
///////////////////////////////////////////////
end of code
//////////////////////////////////////////////
Explanation:
Want
impl::CClass1<impl::CClass0<CClass> >;
and running g.Init();
CClass1::Init();
CClass0::Init();
CClass::Init();
using CMetaFunction1 everything is OK.
but CMetaFunction2 gives
CClass0::Init();
CClass::Init();
WHY ???
Tested on VC++7.0 and GNU Dev-C++
P.S. when use my own lamda function
Both variants works OK.
///////////////////////////////////////////////
template <template <typename> class TBase> struct lambda
{
template <typename T> struct apply
{
typedef TBase<T> type;
};
};
typedef lambda<impl::CClass0> CClass0;
typedef lambda<impl::CClass1> CClass1;
///////////////////////////////////////////////
--Sincerely Yours,--
--\ SergeY /--
--<>\\\ PisarchiK ///<>--
--<>()<>--Never surrendeR--<>()<>--
mailto:Sergey_pisarchiK_at_[hidden]
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk