Page 1 of 2

vector of vectors... Yes it sounds crazy

Posted: Sat Apr 26, 2008 9:51 am
by suthers
I was just trying the code:

Code: Select all

vector<vector> diff_mem;
But it doesn'twork, it says expecting type, got 'vector'.
Is it possible to create a vector of vectors, if not what do you sudgest as an alternative?
(I can't use an array, the memory storage I requier needs a varriable storage capacity)
Thanks in advance,

Jules

Posted: Sat Apr 26, 2008 9:54 am
by Combuster
You didn't instantiate the template in the second vector:
vector<vector<this_bit_is_missing>>

Posted: Sat Apr 26, 2008 11:22 am
by suthers
Thanks, :oops:
Jules

Posted: Sat Apr 26, 2008 5:30 pm
by Zacariaz

Code: Select all

std::vector<std::vecotr<T> > Name;
Just remember the space between the > > otherwise it will be interpeted as a bitwise operator.

Posted: Sun Apr 27, 2008 12:51 am
by pcmattman
Zacariaz wrote:

Code: Select all

std::vector<std::vecotr<T> > Name;
Just remember the space between the > > otherwise it will be interpeted as a bitwise operator.
No, you shouldn't need the space. G++ might be different, but Visual C++ works with no space:

Code: Select all

std::vector<std::vector<int>> a;
Result:

Code: Select all

1>------ Build started: Project: ST_VC05, Configuration: Debug Win32 ------
1>Compiling...
1>SurfaceTension.cpp
1>Build log was saved at "file://d:\programming\c++\games\SurfaceTension\ST_VC05\ST_VC05\Debug\BuildLog.htm"
1>ST_VC05 - 0 error(s), 0 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
Trust me - it works without the space, and you spelt vector wrong too.

Note: don't mind the naming on the files, I used my game engine because it meant I didn't need to write a whole new test program :P.

Posted: Sun Apr 27, 2008 3:47 am
by bluecode
pcmattman wrote:
Zacariaz wrote:

Code: Select all

std::vector<std::vecotr<T> > Name;
Just remember the space between the > > otherwise it will be interpeted as a bitwise operator.
No, you shouldn't need the space. G++ might be different, but Visual C++ works with no space:
Without spaces it is not ISO C++98/03 compliant, but this will be valid in C++0x.

Posted: Sun Apr 27, 2008 3:51 am
by pcmattman
Okay, this just shows us again how un-compliant VC++ is now :D.

Can someone try without spaces in G++ and see what happens?

Posted: Sun Apr 27, 2008 5:48 am
by Hamster1800
~ % g++ foo.cpp
foo.cpp: In function 'int main()':
foo.cpp:6: error: '>>' should be '> >' within a nested template argument list

At least it tells you exactly what's wrong :)

Posted: Sun Apr 27, 2008 1:35 pm
by bluecode
G++ will compile the code in the new c++0x mode, that was added in the 3.3 release. G++ supports some smaller pieces of the upcoming standard in that mode.

edit: actually it is the 4.3 release (not 4.4 as I wrote before).
Okay, this just shows us again how un-compliant VC++ is now
Let's be fair here, imho this is a good thing. I guess it would (it at least should) actually warn you about the non-compliant code if you turn up the warnings, etc...

Posted: Sun Apr 27, 2008 7:18 pm
by B.E
bluecode wrote:Let's be fair here, imho this is a good thing.
Please explain?

Posted: Sun Apr 27, 2008 10:09 pm
by bluecode
B.E wrote:
bluecode wrote:Let's be fair here, imho this is a good thing.
Please explain?
I assume, that there is a switch to turn on warnings for non-ISO (C++98 or C++03) compliant code like this, but I don't know actually, because I don't use VC++. Just like gcc's -std=c89, -std=c99, -std=c++98 and the new -std=c++0x. None of these options is the default for compilation with gcc either. The default currently is -std=gnu89 and -std=gnu++98. So basically what I am trying to say is, that gcc/g++ allows you to write non-compliant code by default (VC++, too), but there is an option to turn on warnings/errors (I assume there is for VC++, too).
Plus, it will be in the upcoming standard anyway (C++0x).

Posted: Mon Apr 28, 2008 8:03 am
by Zacariaz
no matter what it doesn't work in my compiler without the space and it also makes sence to me that it should be there.

Posted: Tue Apr 29, 2008 5:38 am
by edfed
vector of vector don't sound crazy at all.
ivt and idt have frequentlly this.

for example, the int10h have many sub vectors.

int80h in linux have a lot of sub vectors.

if there are a lot of sub vectors ( more than 3 ), the best is the lookup table because of optimal execution. it is faster to make this than to make a string of cmp + je ???

Code: Select all

...
mov eax,subvector
int 69
...
int69:
shl eax,2
cmp eax,[.tablesize]
jge .error
lea [eax+.table]
call eax
...
.error
mov eax,-1
iret
...
.tablesize dd @f-$-4
.table 
dd sub0
dd sub1
dd sub3
dd sub4
@@:

Posted: Tue Apr 29, 2008 6:02 am
by Korona
A vector is an array-like data structure (that dynamically resizes itself) in this case. It's not an entry in some kind of lookup table.

Posted: Tue Apr 29, 2008 6:58 am
by edfed
^
|
this is an array like data structure that can be resized.
lookup table is just a method of access, using the argument as offset in the table.

the simple method of lookup tabel is not appliable in the case of little amount of subvectors.

it is prefered to always put the size of the "lookup" table somewhere, just to prevent overflow.