vector of vectors... Yes it sounds crazy

Programming, for all ages and all languages.
User avatar
suthers
Member
Member
Posts: 672
Joined: Tue Feb 20, 2007 3:00 pm
Location: London UK
Contact:

vector of vectors... Yes it sounds crazy

Post 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
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

You didn't instantiate the template in the second vector:
vector<vector<this_bit_is_missing>>
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
suthers
Member
Member
Posts: 672
Joined: Tue Feb 20, 2007 3:00 pm
Location: London UK
Contact:

Post by suthers »

Thanks, :oops:
Jules
User avatar
Zacariaz
Member
Member
Posts: 1069
Joined: Tue May 22, 2007 2:36 pm
Contact:

Post 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.
This was supposed to be a cool signature...
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post 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.
User avatar
bluecode
Member
Member
Posts: 202
Joined: Wed Nov 17, 2004 12:00 am
Location: Germany
Contact:

Post 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.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post 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?
Hamster1800
Posts: 14
Joined: Wed Apr 16, 2008 5:12 pm

Post 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 :)
User avatar
bluecode
Member
Member
Posts: 202
Joined: Wed Nov 17, 2004 12:00 am
Location: Germany
Contact:

Post 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...
User avatar
B.E
Member
Member
Posts: 275
Joined: Sat Oct 21, 2006 5:29 pm
Location: Brisbane Australia
Contact:

Post by B.E »

bluecode wrote:Let's be fair here, imho this is a good thing.
Please explain?
Image
Microsoft: "let everyone run after us. We'll just INNOV~1"
User avatar
bluecode
Member
Member
Posts: 202
Joined: Wed Nov 17, 2004 12:00 am
Location: Germany
Contact:

Post 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).
User avatar
Zacariaz
Member
Member
Posts: 1069
Joined: Tue May 22, 2007 2:36 pm
Contact:

Post 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.
This was supposed to be a cool signature...
User avatar
edfed
Member
Member
Posts: 42
Joined: Wed Apr 09, 2008 5:44 pm
Location: Mars

Post 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
@@:
welcome in my dream.
Korona
Member
Member
Posts: 1000
Joined: Thu May 17, 2007 1:27 pm
Contact:

Post 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.
User avatar
edfed
Member
Member
Posts: 42
Joined: Wed Apr 09, 2008 5:44 pm
Location: Mars

Post 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.
welcome in my dream.
Post Reply