Function template overload resolution, dependent and non-dependent parameters

后端 未结 2 2224
野的像风
野的像风 2021-02-15 19:44

Given the following program

#include 

template struct id { using type = T; };

template
int func(T1, T2         


        
2条回答
  •  醉梦人生
    2021-02-15 20:06

    The following func overload

    // Denote as overload F.
    template
    int func(typename id::type, typename id::type) { return 1; }
    

    is more specialized than the following func overload

    // Denote as overload G.
    template
    int func(T1, T2) { return 0; }
    

    thus, the former is chosen by overload resolution.


    (All ISO Standard references below refer to N4659: March 2017 post-Kona working draft/C++17 DIS)

    The partial ordering of the G and F overloads of func is governed by:

    • [temp.func.order]/2, [temp.func.order]/3 and [temp.func.order]/4, and
    • [temp.deduct.partial]/2 and [temp.deduct.partial]/10.

提交回复
热议问题