c++ - Can a forwarding reference be aliased with an alias template? -


this continuation of previous question:

can identity alias template forwarding reference?

it seems following code works in both clang 3.7.0 (demo) , gcc 6.0.0 (demo):

template <class t> using forwarding_reference = t&&;  template <class t> void foo(forwarding_reference<t>) {}  int main() {   int i{};   foo(i);   foo(1); } 

are compilers right substitute alias template forwarding reference , fancy way of writing one?

this indeed standard compliant. §14.5.7/2:

when template-id refers specialization of alias template, it equivalent associated type obtained substitution of template-arguments template-parameters in type-id of alias template.

now, consider during template argument deduction, type of parameter (in terms of template parameters) inspected - §14.8.2.1/1:

template argument deduction done comparing each function template parameter type (call p) type of corresponding argument of call (call a) described below.

according first quote, type of parameter, i.e. forwarding_reference<t>, equivalent t&&. hence p t&& , there can no difference regarding deduction.

this same conclusion made committee in defect report concerning exact scenario, #1700:

because types of function parameters same, regardless of whether written directly or via alias template, deduction must handled same way in both cases.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -