问题描述
我有以下 C++14 lambda
#include <boost/optional.hpp>
int main(){
auto foo = [](auto && t)
{
using T = decltype(t);
return boost::optional<T>(std::forward<T>(t));
};
// This is fine because i is lvalue
auto i = 10;
foo(i);
// This fails because i is rvalue
foo(10);
}
首先要注意 boost::optional 可以包含左值引用,但不能包含右值引用。
是否可以使用上述通用 lambda 将右值作为副本进行处理。我想要的是一些聪明的东西
using T = std::decay_if_rvalue<decltype(t)>::type
有什么开箱即用的东西吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)