C++11 static_assert and template instantiation

后端 未结 5 1030
执念已碎
执念已碎 2020-11-29 03:41

In C++11, should the operation of static_assert within a template depend on whether that template has been instantiated or not? For example, with the following code

5条回答
  •  温柔的废话
    2020-11-29 04:15

    I used a helper function to make the false dependent on the template parameter:

    template 
    bool dependentFalse()
    {
        return false;
    }
    
    template
    Foo foo()
    {
        static_assert(dependentFalse(), "this template shouldn't be instantiated");
    }
    

提交回复
热议问题