C++ 创建与推断参数类型相同的局部变量的最简单方法是什么?

C++ 创建与推断参数类型相同的局部变量的最简单方法是什么?,c++,c++11,lambda,auto,template-argument-deduction,C++,C++11,Lambda,Auto,Template Argument Deduction,即: 到目前为止,我正在使用: [](auto const& foo) { ??? bar; // should be same base type as foo, minus const& } typename std::remove\u const::类型组合 但我真的希望有一个更容易的选择 std::decay::type,或decay\t,如果您的std库已更新 它模拟各种函数参数衰减。它处理arg是否是对函数的引用。在引用数组时,它也会生成一个指针,这是不太

即:

到目前为止,我正在使用:

[](auto const& foo) {
    ??? bar; // should be same base type as foo, minus const&
}
typename std::remove\u const::类型组合
但我真的希望有一个更容易的选择

std::decay::type
,或
decay\t
,如果您的
std
库已更新

它模拟各种函数参数衰减。它处理arg是否是对函数的引用。在引用数组时,它也会生成一个指针,这是不太理想的


如果你想以不同的方式处理这些问题,你必须自己动手。

据我所知,我是
auto
类型推断语义,但我需要使用
decltype
,因为我没有指定表达式。他们为反向问题引入了
decltype(auto)foo=bar
,但现在我想要
decltype(bar)foo;)明亮的是的,它支持
std::decation\t
,因此更好。
typename std::remove_const<typename std::remove_reference<decltype(foo)>::type>::type combination