读loki有感,TYPEList原理

读loki有感,TYPEList原理
问题1,简化版的TYPEList,只支持int型
template<int n>
class TYPEList
{
public:
 int Head;
 TYPEList<n⑴> Tail;

};

template<>
class TYPEList<0>
{
public:
 int Tail;
 int Head; 
};

测试代码
TYPEList<0> l0;
 l0.Head = 1;
 l0.Tail = 2;

TYPEList<2> l2;
l2.Head = 3;
l2.Tail.Head = 4;
l2.Tail.Tail.Head = 5;
l2.Tail.Tail.Tail = 6;

问题2:可以同过GetAt(int)获得值
template<int n>
class TYPEList
{
public:
 int Head;
 TYPEList<n⑴> Tail;
 int GetAt(int index )
 {
  if( n+1 == index )
   return Head;
  return Tail.GetAt(index);
 }
};

template<>
class TYPEList<0>
{
public:
 int GetAt(int index)
 {
  if( 1 == index )
   return Tail;
  return Head;
 }
 int Tail;
 int Head; 
};
测试代码
TYPEList<0> l0;
 l0.Head = 1;
 l0.Tail = 2;

 TYPEList<2> l2;
 l2.Head = 3;
 l2.Tail.Head = 4;
 l2.Tail.Tail.Head = 5;
 l2.Tail.Tail.Tail = 6;

 int i1 = l2.GetAt(0);
 int i2 = l2.GetAt(1);
 int i3 = l2.GetAt(2);
 int i4 = l2.GetAt(3);

问题3,类型不再限于int,但最多集成3个变量。

class NullType
{
};

template <class T, class U>
struct Typelist
{
 T Head;
 U Tail;
};

template <typename T1  = NullType, typename T2  = NullType, typename T3  = NullType >

struct MakeTypelist

private:  
 typedef typename MakeTypelist< T2 ,T3>::Result TailResult; 
public:  
 typedef Typelist<T1, TailResult> Result; };

template<> 
struct MakeTypelist<> 
 {  
  typedef NullType Result;
 };

测试代码:
MakeTypelist<ULONG,CString,int>::Result User,User2;

 User.Head = 1;
 User.Tail.Head = "何志丹";
 User.Tail.Tail.Head = 35;

 User2 = User;

 

 template <class AtomicType, template <class> class GenFunc>
    struct IterateTypes
   {    template<class II>
    void operator()(II ii)
       {   
    GenFunc<AtomicType> genfunc;
        *ii = genfunc();
        ++ii; //Is this even needed?
        }
    };

波比源码 – 精品源码模版分享 | www.bobi11.com
1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长!
2. 分享目的仅供大家学习和交流,您必须在下载后24小时内删除!
3. 不得使用于非法商业用途,不得违反国家法律。否则后果自负!
4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解!
5. 如有链接无法下载、失效或广告,请联系管理员处理!
6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需!
7. 本站源码并不保证全部能正常使用,仅供有技术基础的人学习研究,请谨慎下载
8. 如遇到加密压缩包,请使用WINRAR解压,如遇到无法解压的请联系管理员!

波比源码 » 读loki有感,TYPEList原理

114 评论

  1. buy provera online cheap microzide 25mg drug buy periactin 4mg without prescription

  2. no deposit casino online roulette game free casino games no registration no download

  3. order biaxin 250mg for sale oral antivert order antivert 25mg pill

  4. buy albuterol cipro usa ciprofloxacin us

  5. cialis tadalafil 40mg Approved cialis online casino for real cash

  6. online slots for real money slot games free poker online for real money

  7. cheap benicar 20mg verapamil cheap buy divalproex 250mg pill

  8. purchase diamox without prescription azathioprine pills purchase azathioprine generic

  9. lanoxin online order oral digoxin order generic molnupiravir 200mg

  10. cialis 10mg without prescription Cialis buy herbal ed pills

  11. order generic oxybutynin 5mg ditropan order buy oxcarbazepine 300mg without prescription

  12. where to buy duloxetine without a prescription glipizide canada buy nootropil 800 mg without prescription

  13. order leflunomide 10mg pill sildenafil 100mg order generic azulfidine 500mg

  14. temovate tablet buspar pill amiodarone 100mg canada

  15. buy aristocort paypal loratadine oral purchase claritin online

  16. oral rosuvastatin crestor pills purchase motilium generic

  17. where can i buy spironolactone aldactone cheap valtrex cheap

  18. tacrolimus 5mg usa requip pills order requip pills

  19. valsartan 160mg drug cheap diovan purchase ipratropium online cheap

  20. order decadron 0,5 mg without prescription starlix buy online cost starlix 120mg

  21. zyban 150mg generic cost zyban atomoxetine brand

  22. order ciplox 500mg pills duricef oral cheap cefadroxil 250mg

  23. fluoxetine 40mg generic sarafem pill letrozole over the counter

评论已关闭

Hi, 如果你对这款模板有疑问,可以跟我联系哦!

联系站长
赞助VIP 享更多特权,建议使用 QQ 登录
喜欢我嘛?喜欢就按“ctrl+D”收藏我吧!♡