Temporary const array not binding to rvalue reference

元气小坏坏 提交于 2019-12-05 01:59:06
A. Mikhaylov

According to the standard §12.2 [class.temporary]:

Temporaries of class type are created in various contexts: binding a reference to a prvalue (8.5.3), returning a prvalue (6.6.3), a conversion that creates a prvalue (4.1, 5.2.9, 5.2.11, 5.4), throwing an exception (15.1), entering a handler (15.3), and in some initializations (8.5).

So id<int const[]>{1, 2, 3, 4, 5} is a temporary and therefore is an prvalue §3.10 [basic.lval]:

An rvalue (so called, historically, because rvalues could appear on the right-hand side of an assignment expression) is an xvalue, a temporary object (12.2) or subobject thereof, or a value that is not associated with an object.

A prvalue (“pure” rvalue) is an rvalue that is not an xvalue.

Hence shall be selected overloaded function with rvalue reference argument.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!