Set of vectors and...

A

Amit

Hello.

I am having some problem organizing a set of vectors. The vectors itself,
could contain a pointer( say integer pointer) or could contain another
object MyClass.

1>So, first of all, is there anyway where I can accomodate both the vector
Right now, I am having them as two different set dayatypes.

2>Coming to the compare_func and other things, lets assume this following
set type
set<vector<int*>, compare_func > for simplicity. Right now what I have for
the compare_func, what I have is something that isnt correct( I know that).

template <typename Cont>
struct less_vector
{
bool operator()( const Cont& c1, const Cont& c2)
{
return (c1 < c2);
}
};

and therefore I use set<vector<int*>, less_vector<vector<int*> >.

The problem as evident here is the comparison function compares the two
vector types which would do a lexicographical_compare on the pointers.
But what I really want is another comparison( and a set of comparison
functions that I could overload), which would

1>Do lexicographical compare based on the actual elements of the array that
int* in the vector points to.
2>Sort the vectors based on the addition of the elements in the array that
int* point to
3>blah blah blah...

Is there anyway of doing this ? I know it would mean sending a predicate, to
the less_vector Function Object, but I am not able to get the syntax
correct. The part
where I am confused is how do I use the iterator and the iterator_traits to
do that.

3>Last but not the least, How do I iterate over the set and through the
elements pointed to by the int* of the vector within the set.

Right now I use the for loop,

for(s1::iterator pos = s.begin(); pos != s.end(); pos++)
{
cout << "New Vector" << "\n" ;
transform((*pos).begin(), (*pos).end(), std::eek:stream_iterator<int>(cout,
"\n"),
Dereference());
}

The Dererence just does a derefernce of the int*. For sake of simplicity, I
have assumed that the the int* in the vector points only to one integer, so
you can do *iter in the Dereference and return the value.

What I am looking for is something like a single shot transform function
iterating over the entire thing
transform(s.begin(), s.end(), std::eek:stream_iterator<int>(cout, "\n"),
DereferenceandDisplaythevectorelemnts());

Thanks for reading and Thanks in advance for any solutions.
 
A

Andre Kostur

Hello.

I am having some problem organizing a set of vectors. The vectors
itself, could contain a pointer( say integer pointer) or could contain
another object MyClass.

A set of vectors, huh? The first question I'd have is whether it makes any
sense at all to have an ordering on the vectors... ie: trying to make an
ordering between

{ 1, 2 }, { 2, 1 }, {}, { 1 }

(which, should end up as {}, { 1 }, { 1, 2 }, { 2, 1 } )

Now even assuming that ordering the vectors makes sense, you're not allowed
to modify the vectors inside the set. You'd have to erase the existing
vector and insert a new one (vector) in order to add an item to it.

Third, how do you locate the vector that you wish to insert a new item
into? (Assuming that the set of vectors is doing what you expect it to)
 
A

Amit

Andre Kostur said:
A set of vectors, huh? The first question I'd have is whether it makes any
sense at all to have an ordering on the vectors... ie: trying to make an
ordering between
If you get a bunch of instructions which could be opcodes(dwords for
instance) and
they come down as an array, that I feed into a vector.
These vectors could have 5 instructons or 10 instructions or 100
instructions.
Further more, Based on the availability of the h/w, I can break the 100
instructions into instruction sets of 10.
The question of modifying the vector once inserted into the set doesnt even
come into the picture if you have read my problem.
Thanks for reading.
 
A

Andre Kostur

If you get a bunch of instructions which could be opcodes(dwords for
instance) and
they come down as an array, that I feed into a vector.
These vectors could have 5 instructons or 10 instructions or 100
instructions.
Further more, Based on the availability of the h/w, I can break the
100 instructions into instruction sets of 10.
The question of modifying the vector once inserted into the set doesnt
even come into the picture if you have read my problem.

Still not making any sense to me.

Let's assume that you get 3 of these arrays (call them array A, B, and
C), which get turned into vectors vA, vB, and vC. Also let's assume that
they have 5 elements each. How would you determine what the correct
ordering of vA, vB, vC is?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top