samedi 16 février 2019

c++ template specialization with template

can someone explain me why does c++ requires a template argument when both out member functions (from the template and from the specialization) need a template, because I'm not getting it and google is not helping. Must be c++11 but have the same error with c++1z.
I'm using g++ 7.3.0

#include <iostream>

using namespace std;

using Out=ostream;

struct O {};

template<typename O=O>
struct Static:public O {
  template<const char** text>
  struct Text {
    static inline void out(Out& o) {o<<text[0];}
  };
};

template<typename O>
struct Endl {
  static inline void out(Out& o) {O::out(o);o<<endl;}
};

template<typename O,typename... OO>
struct MenuData {
  using Head=O;
  using Tail=MenuData<OO...>;
  template<template<typename> class P>
  static inline void out(Out& o) {
    P<O>::out(o);
    Tail::out<P>(o);//<--?!?!?!
  }
};

template<typename O,typename OO>
struct MenuData<O,OO> {
  using Head=O;
  using Last=OO;
  template<template<typename> class P>
  static inline void out(Out& o) {P<O>::out(o);P<Last>::out(o);}
};

/////////////////////////////////////////////////////////
const char* op1Text="Op1";
using op1=Static<>::Text<&op1Text>;

const char* op2Text="Op2";
using op2=Static<>::Text<&op2Text>;

const char* op3Text="Op3";
using op3=Static<>::Text<&op3Text>;

using MainMenu=MenuData<op1,op2,op3>;

int main(int argc,char** argv) {
  MainMenu::out<Endl>(cout);
  cout<<endl;
}

Aucun commentaire:

Enregistrer un commentaire