2015年3月30日星期一

Find the bug in this code(2)

The wrong code looks like this:







    First, let me explain the key word constexpr: it is for evaluating the value of the function or variable at compile time. When used in an object declaration it implies const, instead used in an function declaration it implies inline.
    Here, we define a struct Int with a variable and a function called iter. In main function, we instantiate the template. 
    The declaration template<int i> constexpr auto iter(...)->... is instantiated with i = 0, which forces the evaluation of decltype(iter(Int<-1>{})). The reason for this is Since definition instantiation occures after template overload resolution. So the template iter<0> is never instantiated. Both triggers infinite instantiation. How should we change it?









Here, you go! 

没有评论:

发表评论