目前,我可以像这样编写 range-v3 视图:
auto v = ranges::view::reverse | ranges::view::filter([](int l){return l>5;});
但是如果我想从函数中返回 v,我需要知道它的类型。range-v3 视图的类型是什么?
从 C++14 开始,您可以将auto
其用作函数的返回类型,它将被推导出:
auto f() {
return ranges::view::reverse | ranges::view::filter([](int l){return l>5;});
}
// f's return type is the type of the return expression, exactly as is I had:
// auto returnValue = return-expression;
// where f's type is decltype(returnValue)
唯一的缺点是 的定义f
必须出现在您使用它的同一个 TU 中。