C++ 11(和C++ 14)引入了针对通用编程的其他语言结构和改进.这些功能包括:
我在浏览较早草案的的C++ 14规范(现在更新文本)和码中的示例中§20.5.1,编译时整数序列,我发现有趣和奇特.
template<class F, class Tuple, std::size_t... I>
decltype(auto) apply_impl(F&& f, Tuple&& t, index_sequence<I...>) {
return std::forward<F>(f)(std::get<I>(std::forward<Tuple>(t))...);
}
template<class F, class Tuple>
decltype(auto) apply(F&& f, Tuple&& t) {
using Indices = make_index_sequence<std::tuple_size<Tuple>::value>;
return apply_impl(std::forward<F>(f), std::forward<Tuple>(t), Indices());
}
Run Code Online (Sandbox Code Playgroud)
在线这里[intseq.general]/2.
题
f
在apply_impl
被转发,即为什么std::forward<F>(f)(std::get...
?f(std::get...
?