473,406 Members | 2,633 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Set of vectors and...

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
types into a single set. Something like a set<vector<void*>, my_compare func
.

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::ostream_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::ostream_iterator<int>(cout, "\n"),
DereferenceandDisplaythevectorelemnts());

Thanks for reading and Thanks in advance for any solutions.
Jul 23 '05 #1
3 3217
"Amit" <am***********@intel.com> wrote in
news:d0**********@news01.intel.com:
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)

Jul 23 '05 #2

"Andre Kostur" <nn******@kostur.net> wrote in message
news:Xn*******************************@207.35.177. 135...
"Amit" <am***********@intel.com> wrote in
news:d0**********@news01.intel.com:
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 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.

{ 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)

Jul 23 '05 #3
"Amit" <am***********@intel.com> wrote in
news:d0**********@news01.intel.com:

"Andre Kostur" <nn******@kostur.net> wrote in message
news:Xn*******************************@207.35.177. 135...
"Amit" <am***********@intel.com> wrote in
news:d0**********@news01.intel.com:
> 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

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?
Jul 23 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Michael Aramini | last post by:
I need to represent 1D and 2D arrays of numeric or bool types in a C++ program. The sizes of the arrays in my intended application are dynamic in the sense that they are not known at compile time,...
5
by: Pratyush | last post by:
Hi, Suppose there is a vector of objects of class A, i.e., std::vector<A> vec_A(N); The class A satisifies all the STL vector requirements. Now I wish to add some attributes for each of the...
5
by: Computer Whizz | last post by:
I was reading through Accelerated C++ at work when I read through the first mention of Vectors, giving us certain functions etc. Is there any benefit of Arrays over Vectors? Since all Vectors...
19
by: chris | last post by:
Hello, I've recently been trying to understand the various structures supplied by c++, and the one I find most confusing is deque. One quick question about this. It seems most implementations...
4
by: Dr. J.K. Becker | last post by:
Hi all, I have vectors that holds pointers to other vectors, like so: vector<whatever> x; vector<whatever*> z; z=&x; Now I add something to x
5
by: madhu | last post by:
http://msdn2.microsoft.com/en-us/library/fs5a18ce(VS.80).aspx vector <intv1; v1.push_back( 10 ); //adds 10 to the tail v1.push_back( 20 ); //adds 20 to the tail cout << "The size of v1 is " <<...
2
by: wuzertheloser | last post by:
Use the program skeleton below (starting with #include <stdio.h>) as the starting point for quiz4. Add the necessary code to the functions prob1() and prob2(), and add the other 2 functions, as...
1
by: Rob | last post by:
How would I do this? I want to be able to handle vectors of many different types of data and vectors that can contain any number of other vectors of data. Currently, I have a templated...
2
by: joeme | last post by:
How would one using STL do the following tasks: 1) merge 2 sorted vectors with dupes, result shall be sorted 2) merge 2 sorted vectors without dupes, result shall be sorted 3) merge 2...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.