I want to initialize an array of template sizes without default constructors, as shown in the following code:
#include <array> template<std::size_t N> class Foo { public: class Bar { Foo<N> & _super; public: Bar(Foo<N> *super) : _super(*super) { } }; std::array<Bar, N> _array; Foo(void) : _array{{}} // We need {this, ...} N times { } }; int main(void) { Foo<3> foo; (void)foo; return 0; }
Can I say: "I want an array of N objects, all initialized using the same parameter"? I think there is a way of meta-programming templates, but I cannot figure out how to do this.
source share