200分,送!(解决了)

yshuise yshuise 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
#include "stdafx.h"
#include <iostream>
#include <string>
#include <boost/mpl/vector.hpp>
#include <boost/mpl/push_back.hpp>
#include <boost/mpl/begin_end.hpp>
#include <boost/mpl/at.hpp>
#include <boost/mpl/erase.hpp>
#include <boost/mpl/pop_front.hpp>
#include <boost/mpl/int.hpp>
#include <boost/mpl/deref.hpp>
#include <boost/mpl/front.hpp>

using std::string;
using std::cout;
using std::endl;
using boost::mpl::at ;
using boost::mpl::int_;
using boost::mpl::pop_front;
using boost::mpl::vector;
using boost::mpl::deref;
using boost::mpl::begin;
using boost::mpl::front;


struct NullType{ };

template<int N>
struct Int2Type
{
enum{ vaule = N };
};

template <class T>
struct Holder{
typename T vaule;
};
template <class TList, template<class> class Unit>
class GenScatterHierarchy;//主模板

template<class T1, class T2, template<class> class Unit>
class GenScatterHierarchy<typename begin<vector<T1,T2>>::type , Unit>//对主模进行特化。
: public GenScatterHierarchy<typename front<vector<T1,T2>>::type, Unit>
, public GenScatterHierarchy<typename pop_front<vector<T1,T2>>::type, Unit>
{

};

template<class ATomicType, template<class> class Unit>
class GenScatterHierarchy : public Unit<ATomicType>
{

};

template<template<class> class Unit>
class GenScatterHierarchy<NullType, Unit>{

};



// template<class TList, template<class> class Unit>
// Unit< at<TList, int_<0>>>& FieldHelper(
// GenScatterHierarchy<TList,Unit>& obj, Int2Type<0> )
// {
// GenScatterHierarchy<at<TList, int_<0>>, Unit>& leftBase = obj;
// return leftBase;
// };
//
// template<int i, class TList, template<class> class Unit>
// Unit< at<TList, int_<i>>>& FieldHelper(
// GenScatterHierarchy<TList, Unit>& obj, Int2Type<i>)
// {
// GenScatterHierarchy<pop_front<TList>, Unit>& rightBase = obj;
// return FieldHelper(rightBase, Int2Type<i-1>());
// }
//
// template <int i, class TList, template<class> class Unit>
// Unit< at<TList,int_<i>>>&
// Field (GenScatterHierarchy<TList, Unit>& obj)
// {
// return FieldHelper(obj, Int2Type<i>() );
// }


int _tmain(int argc, _TCHAR* argv[])
{

//typedef GenScatterHierarchy<vector<int, string>, Holder> Info;
// Info obj;
// int b = (static_cast<Holder<int>&>(obj)).vaule;//这种递归仍是可疑,关键是模板特化仍不对。
//deref<begin<vector<int>::type>::type>::type a=9;
//cout<<a<<endl;
return 0;

}

f:\documents and settings\administrator\my documents\visual studio 2005\projects\csdn\csdn\csdn.cpp(48) : error C2764: 'T1' : template parameter not used or deducible in partial specialization 'GenScatterHierarchy<begin<boost::mpl::vector<T0,T1,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na>>::type,Unit>'
f:\documents and settings\administrator\my documents\visual studio 2005\projects\csdn\csdn\csdn.cpp(48) : error C2764: 'T2' : template parameter not used or deducible in partial specialization 'GenScatterHierarchy<begin<boost::mpl::vector<T0,T1,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na,boost::mpl::na>>::type,Unit>'
...全文
评论 127
收藏 已收藏
分享
返回顶部
yshuise
C++ 语言 65,214 成员 250,514 内容