#include <type_traits>
template <int beg, int end> struct static_for {
template <typename Fn> void operator()(Fn const& fn) const {
if (beg < end) {
fn(std::integral_constant<int, beg>());
static_for<beg + 1, end>()(fn);
}
}
};
template <int n> struct static_for<n, n> {
template <typename Fn> void operator()(Fn const& fn) const {}
};
template <int N> int foo() { /*...*/
return N;
}
int main() {
static_for<0, 32>()([&](auto i) {
if (foo<i>() != i) { /* fail... */
}
});
return 0;
}
遇到此错误
错误TypeError:无法读取未定义的属性“ add” 在index.js:5502 在ZoneDelegate.push ... / .. / node_modules / zone.js / dist / zone.js.ZoneDelegate.invokeTask (zone.js:423) 在Object.onInvokeTask(core.js:17290) 在ZoneDelegate.push ... / .. / node_modules / zone.js / dist / zone.js.ZoneDelegate.invokeTask (zone.js:422) 在Zone.push ... / .. / node_modules / zone.js / dist / zone.js.Zone.runTask (zone.js:195) 在推... / .. / node_modules / zone.js / dist / zone.js.ZoneTask.invokeTask (zone.js:498) 在ZoneTask.invoke(zone.js:487) 在计时器(zone.js:2281)