C++11 range for over "tuple"
c++, c++11
Solution
From the error messages you posted, the error is completely unrelated to this passage, and caused by the fact that you are trying to swap `const` `int`. The reason for that is that your `H1[…]` access in the initialiser list is copying the vectors, hence you end up with a temporary object which is implicitly bound to a `const` reference. As a consequence, the members of the vector are `const` as well.
It’s worse than that: even if you fix this error, your code won’t work because you are accessing the wrong type. Your members are initialised as follows:
H1 = new vector<T>[n];
`H1` is a pointer to a single vector. You almost certainly don’t want that since then in your code you access it with an index:
H1[hash_func(n1, val)]
If `hash_func` yields anything other than `0` your code accesses invalid memory.
Why are `H1` and `H2` pointers anyway? Do not use manual memory management. Just use plain vectors.
Problem
I'm trying to implement a hash class using C++11 features. I'm not reusing stl's hash because it's a school assignment. I'm trying to do this: ``` for(auto &h : {H1[hash_func(n1, val)], H2[hash_func(n2, val)]}) { for(auto &x : h) { if(x == val) { swap(x, h.back()); h.pop_back(); } } } ``` `H1` and `H2` are of type `vector<T>*`. When I try to compile this, I get a nasty syntax error I can't even make sense of. If I try `for(auto &h : {H1, H2})` and use `h[hash_func(n1, val)]` instead of `h`, it works (though it's obviously wrong). How can I fix this? (or at least implement it in a manner that's more elegant than writing the same thing twice)