fork(2) download
  1. #include <iostream>
  2. #include <type_traits>
  3.  
  4. using namespace std;
  5.  
  6. template<typename Parser>
  7. struct Module{
  8. using DType = typename Parser::DType;
  9. using OptionsType = int;
  10. };
  11.  
  12. template<typename D, typename Derived = void >
  13. struct Parser{
  14. using DType = D;
  15.  
  16. using DerivedType = typename std::conditional< std::is_same<Derived,void>::value, Parser, Derived>::type;
  17. using ModuleType = Module<DerivedType>;
  18. using ModuleOptions = typename ModuleType::OptionsType; //uncomment this!!
  19. };
  20.  
  21. template<typename D>
  22. struct ParserDerived: Parser<D, ParserDerived<D> >{
  23.  
  24. using Base = Parser<D, ParserDerived<D> >;
  25.  
  26. };
  27.  
  28.  
  29. int main() {
  30. Parser<double> t;
  31.  
  32. ParserDerived<double> d;
  33. }
Compilation error #stdin compilation error #stdout 0s 3292KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of ‘struct Module<ParserDerived<double> >’:
prog.cpp:18:59:   required from ‘struct Parser<double, ParserDerived<double> >’
prog.cpp:22:8:   required from ‘struct ParserDerived<double>’
prog.cpp:32:24:   required from here
prog.cpp:8:41: error: no type named ‘DType’ in ‘struct ParserDerived<double>’
     using DType = typename Parser::DType;
                                         ^
prog.cpp: In function ‘int main()’:
prog.cpp:30:17: warning: unused variable ‘t’ [-Wunused-variable]
  Parser<double> t;
                 ^
prog.cpp:32:24: warning: unused variable ‘d’ [-Wunused-variable]
  ParserDerived<double> d;
                        ^
stdout
Standard output is empty