在从this问题this答案提交张贴此代码:C++:关键字“类型名称”的在此函数中的含义
template <typename... Ts>
typename std::tuple_element<0, std::tuple<Ts...> >::type // or decltype(auto)
callFunction(Ts&&... ts)
{
using type = typename std::tuple_element<0, std::tuple<Ts...> >::type;
auto it = multiCache.find(typeid(type));
assert(it != multiCache.end());
auto&& fn = boost::any_cast<const std::function<type(Ts...)>&>(it->second);
return fn(std::forward<Ts>(ts)...);
}
的typename std::tuple_element<0, std::tuple<Ts...> >::type
含义是,返回的类型相同的第一个元素的第一个元素在Ts...
,对不对?
是的,这是穷人的“索引到类型参数包”。这在这种情况下有点愚蠢,因为你可能只是写'T &&,Ts && ...'函数并直接使用'T'。 –