Explain C++ SFINAE to a non-C++ programmer

前端 未结 5 1068
孤城傲影
孤城傲影 2020-11-27 10:29

What is SFINAE in C++?

Can you please explain it in words understandable to a programmer who is not versed in C++? Also, what concept in a language like Python does

5条回答
  •  盖世英雄少女心
    2020-11-27 10:59

    If you have some overloaded template functions, some of the possible candidates for use may fail to be compilable when template substitution is performed, because the thing being substituted may not have the correct behaviour. This is not considered to be a programming error, the failed templates are simply removed from the set available for that particular parameter.

    I have no idea if Python has a similar feature, and don't really see why a non-C++ programmer should care about this feature. But if you want to learn more about templates, the best book on them is C++ Templates: The Complete Guide.

提交回复
热议问题