In the following example, I need to initialize the std::array in the A::A(H h) constructor initializer list (because class H doesn't have a default constructor), but I can't do it with an initializer list since the array size is a template parameter.
Is there a way around this?
#include <array>
using namespace std;
struct Hash {
const vector<int> &data;
Hash(const vector<int> &data)
: data(data) {
}
uint64_t operator()(int id) const {
return data[id];
}
};
template <class H, size_t N>
class A {
public:
A(H h) {
}
std::array<H, N> hashes;
};
int main () {
vector<int> data{1, 2, 3, 4};
A<Hash, 4> a{Hash(data)};
}