Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cant make a vector of fixed size arrays?

Tags:

c++

I have this odd problem

    vector<unsigned int[3]> tris;
    for (unsigned int i = 0; i < idx.size() - 2; i++) {
        unsigned int push[] = {idx[i], idx[i+1], idx[i+2]};
        tris.push_back(push); //<- this is where it goes belly up
    }

The code piece is supposed to unravel a triangle strip index list into triangle indices but wont compile under vs10. Thoughts?

like image 998
Jake Freelander Avatar asked Jun 06 '13 19:06

Jake Freelander


1 Answers

No, unless you wrap your arrays into a struct or use something like std::array.

The naked C-style array type is not copyable or assignable, which makes it ineligible to serve as a standard container element.

P.S. It should be noted though that C++11 switched to a more elaborate (per-method) approach to specifying requirements to container element type, instead of the more broad approach used by C++03. The above ineligibility claim is based on C++03. I'm not ready to say that it is so unconditionally true for C++11 as well... But it is certainly true even in C++11 if you insist on using push_back in your code.

P.P.S. In C++11 one can probably get away with std::list of naked C-style arrays and using emplace to construct new elements. But not with std::vector.

like image 61
AnT Avatar answered Oct 08 '22 20:10

AnT