I know how to do this the long way so to speak:
#include <vector>
int main() {
// Simple vector of ints = resized to 1k elements
std::vector<int> ints;
ints.resize( 1000 ); // Easy enough
// nested vector of ints 1k vectors each with 1k elements
std::vector<std::vector<ints>> vecInts;
vecInts.resize( 1000 );
for ( auto& a : vecInts ) {
a.resize( 1000 );
}
// Again easy enough.
}
Now instead of typing it out like that I would like to use typedefs
#include <vector>
typedef std::vector<int> Ints;
typedef std::vector<Ints> vecInts;
int main() {
vecInts a;
a.resize( 1000 ); // seems okay
// Assuming this would work...
for ( auto& n : a ) {
n.resize( 1000 );
}
}
My question is does the 2nd code snippet do what is expected and is it equivalent to the 1st code snippet or am I missing something?
Second quick question does 1k * 1k
exceed the size limits of std::vector
?
Aucun commentaire:
Enregistrer un commentaire