std::vector of std::vectors?
Hi,
Just a quick question, how do you create an std::vector where each element is an std::vector? I tried
std::vector <std::vector<Polygon>> polyList;
but it didn't compile. Any ideas?
[EDIT - I edited the code line to make it show up, but didn't change the spacing so that Sneftel's answer is still correct and makes sense. ]
[edited by - Kylotan on September 12, 2002 7:58:40 PM]
A template can only be templated of a solved template.
If brute force does not solve your problem....you''re not using enough!
If brute force does not solve your problem....you''re not using enough!
When nesting template specifications, put a space between adjacent angle brackets, or the compiler will recognize it as another operator.
Don't listen to me. I've had too much coffee.
[edited by - sneftel on September 12, 2002 7:53:18 PM]
vector<vector<int>> v; // NO!!!vector<vector<int> > v; // YES!!!
Don't listen to me. I've had too much coffee.
[edited by - sneftel on September 12, 2002 7:53:18 PM]
Because >> is parsed as a single token. This is necessary. e.g. for vector<std::bitset<1>>3> >. If >> was considered the end of the template, this would be illegal code.
Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
quote:
Because >> is parsed as a single token. This is necessary. e.g. for vector<std::bitset<1>>3> >. If >> was considered the end of the template, this would be illegal code.
This is because C++ parses the largest token possible, yes? So
++++a;
would be
++(++a);
and
+++++a;
would be
++(++(+a));
right?
Hold that thought, I remember a huge e-mail our head programmer at work wrote on the subject...
I think what he said is that the compiler parses the file for tokens first and then resolves what''s actually going on... or something to that effect...
I think what he said is that the compiler parses the file for tokens first and then resolves what''s actually going on... or something to that effect...
quote:Original post by Zipster
Hold that thought, I remember a huge e-mail our head programmer at work wrote on the subject...
I think what he said is that the compiler parses the file for tokens first and then resolves what''s actually going on... or something to that effect...
Right. It tokenizes it before it does stuff with it. Which means it''s okay that angle brackets look like greater-than and less-than, since context can determine which is which, but once you''re actually doing stuff with the tokens, it''s already too late to decide that your bitwise shift is actually two angle brackets.
Don''t listen to me. I''ve had too much coffee.
Yeah, the lexer can more easily tell it is in a template context when it''s opening the template parameter block, because it either has ''template'' or ''typename Foo'' (or ''class Foo'') before, than when it is closing it, since it can have an integral parameter ( case of bitset<10> ) for which both the bitshift and the two template endings would be valid tokens. In the interest of being able to write the previously posted code, the bitshift has been decided to take precedence.
Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement