Static assertions and SFINAE

前端 未结 2 1256
北恋
北恋 2020-12-30 09:36

Consider this:

template 
struct hash
{
     static_assert(false,\"Not implemented.\");
};

struct unhashable {};

template 

        
2条回答
  •  梦谈多话
    2020-12-30 10:08

    On gcc 4.7, compilation fails. I am pretty positive though that this will compile ok in gcc 4.8 (but cannot check at this very moment). Who is right?

    The condition in your static assertion does not depend on any template parameter. Therefore, the compiler can immediately evaluate it to false when parsing the template, and realize that the assertion should fire - no matter whether you actually instantiate the template anywhere else.

    The same should be true on any compiler.

提交回复
热议问题