@
bluearc #57 都用上 map 了那不如这样:
```
#include <iostream>
#include <functional>
constexpr int maxN = 100;
class Foo {
public:
static void invoke(int i) {
_mapping[i](i);
}
private:
static std::function<void(int)> _mapping[maxN];
template <int N>
struct FooHelper {
FooHelper() {
_mapping[N] = [](int n) {
std::cout << "Foo<" << N << "> (" << n << ")" << std::endl;
};
}
};
template <int N>
struct Initer : Initer<N-1> {
FooHelper<N> _foo;
};
static Initer<maxN> _initer;
};
template<>
struct Foo::Initer<0> {};
std::function<void(int)> Foo::_mapping[maxN];
Foo::Initer<maxN> Foo::_initer;
int main(){
int n;
std::cin>>n;
Foo::invoke(n);
}
```
虽然感觉也挺丑的