相关疑难解决方法(0)

由于对模板化类型的通用(前向)引用而无法实例化函数模板

通用参考(即"前向参考",c++标准名称)和完善的转发c++11,c++14具有许多重要优势; 看到这里,在这里.

在上面引用的Scott Meyers的文章(链接)中,根据经验表明:

如果变量或参数声明为某个推导类型 T的类型为T &&,则该变量或参数是通用引用.

例1

实际上,使用clang ++我们看到以下代码片段将成功编译-std=c++14:

#include <utility>

template <typename T>
decltype(auto) f(T && t)
{
    return std::forward<T>(t);
}

int        x1 = 1;
int const  x2 = 1;
int&       x3 = x1;
int const& x4 = x2;

// all calls to `f` result in a successful
// binding of T&& to the required types
auto r1 = f …
Run Code Online (Sandbox Code Playgroud)

c++ templates perfect-forwarding c++11 c++14

11
推荐指数
1
解决办法
1053
查看次数

标签 统计

c++ ×1

c++11 ×1

c++14 ×1

perfect-forwarding ×1

templates ×1