即:
[](auto const& foo) {
??? bar; // should be same base type as foo, minus const&
}
到目前为止,我正在使用:
typename std::remove_const<typename std::remove_reference<decltype(foo)>::type>::type combination
但我真的希望有更简单的选择!
最佳答案
std::decay<decltype(whatever)>::type
, 或 decay_t
如果你的 std
库已更新。
它模拟各种函数参数衰减。如果您的 arg 是函数引用,它会处理。在引用数组时,它也会生成一个指针,这不太理想。
如果您想以不同的方式处理这些问题,则必须自己动手。
关于c++ - 创建与推导参数具有相同类型的局部变量的最简单方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24093289/