C++从通用引用中提取实际类型

C++ extract actual type from universal reference

本文关键字:提取 类型 引用 C++      更新时间:2023-10-16

如何提取通用引用的实际类型,如下所示:

template<class T>
void foo(T&& value) {
otherFunction<...>(value);

我想用实际的值类型替换...,即既不T&也不T&&const T&,而只是T.

另外,我真的需要std::forward值吗?因为otherFunction只接受实际值,所以无论如何它都会删除任何类型的引用。那么我不需要std::forward是正确的吗?

使用std::remove_reference.它会把intint&int&&变成int