C++ lazy evaluation with templates

This question already has an answer here:

  • Switch passed type from template 4 answers

  • if(is_recursable<A>::value == 1)
      /* printf("1 %s", typeid(B).name()); */
      lhs.printrec();
    else
      printf("0");
    

    Until constexpr if exists you cannot do this. Reason being is that the compiler must assume that both branches are possible even if one or the other is not reachable--yeah, seems like it should be able to tell, but it's not allowed to by the language. You need to use tag dispatching or some other compile time construct.

    See this answer

    链接地址: http://www.djcxy.com/p/86332.html

    上一篇: 静态变量链接错误

    下一篇: 用模板进行C ++懒惰评估