View Full Version : Problem regarding C++ STL
vermarajeev
26th September 2006, 13:42
Hi guys,
I'm working on a project where I need to remove Qt libraries and use C++ STL.
I need to replace QPtrList::findRef defined in Qt with C++ STL alternative . But unable to get any solution.
For example
I have used STL's find(InputIterator first, InputIterator last, const T& value) to replace QPtrList::find. The code can be seen as below
Defined in Qt3
if( -1 == steps.find( s ) )
Alternative in C++ STL
StepListIterator sIt = find( steps.begin(), steps.end(), s);
if (sIt == steps.end())
{
//not found perform relevant operation
}
Similar way I need to replace Qt's QPtrList::findRef with an C++ STL alternative.
Please help me
Waiting for your reply
Thankx in advance
vermarajeev
27th September 2006, 08:29
Hi guys,
I'm working on a project where I need to remove Qt libraries and use C++ STL.
I need to replace QPtrList::findRef defined in Qt with C++ STL alternative . But unable to get any solution.
For example
I have used STL's find(InputIterator first, InputIterator last, const T& value) to replace QPtrList::find. The code can be seen as below
Defined in Qt3
Qt Code:
if( -1 == steps.find( s ) )
Alternative STL Code:
StepListIterator sIt = find( steps.begin(), steps.end(), s);
if (sIt == steps.end())
{
//not found perform relevant operation
}
Similar way I need to replace Qt's QPtrList::findRef with an C++ STL alternative.
Please help me
This is really improtant to me
Waiting for your reply
Thankx in advance
wysota
27th September 2006, 09:48
What is "s"? If "s" is a pointer, then the implementation you provided is the implementation of findRef and not Find.
vermarajeev
27th September 2006, 14:07
Hi, thankx for your reply
Here are the declarations given
in Qt
typedef QList<SynStep> SynStepList;
typedef QListIterator<SynStep> StepListIterator;
SynStep* s; //where SynStep is a class defined by me
class StepList : public SynStepList
{
};
StepList steps;
if( -1 == steps.find( s ) )
in STL
typedef std::vector<SynStep*> SynStepList;
typedef std::vector<SynStep*>::iterator StepListIterator;
SynStep* s; //where SynStep is a class defined by me
class StepList : public SynStepList
{
};
StepList steps;
StepListIterator sIt = find( steps.begin(), steps.end(), s);
if (sIt == steps.end())
{
//not found perform relevant operation
}
Ok if that is the implementation for FindRef than can you please tell me how can I
implement Find....
wysota
27th September 2006, 16:45
But these declarations are from Qt4 and in the first post you gave Qt3 code.
QPtrList::find compares items referenced by pointers, findRef compares pointers directly, therefore if you want to compare items, you have to convince STL to compare items. I doubt it is directly possible so you'll probably have to subclass or at least create a custom compare functor and tell find() to use it.
jacek
27th September 2006, 16:46
There is no difference between find() and findRef() if you have a vector of pointers.
jacek
27th September 2006, 16:51
Threads merged.
Please don't ask the same question in different section.
bood
28th September 2006, 11:14
There is no difference between find() and findRef() if you have a vector of pointers.
Of course there is.
Diffrenent pointers can point to different objects that have same value.
jacek
28th September 2006, 11:29
Of course there is.
Diffrenent pointers can point to different objects that have same value.
But still, if the value is a pointer, there is no difference, since find() doesn't dereference pointers.
wysota
28th September 2006, 11:40
But still, if the value is a pointer, there is no difference, since find() doesn't dereference pointers.
I guess that for Qt3 with QPtrList it might make a difference. Of course STL doesn't support dedicated lists for pointers, so to port the same behaviour to STL, one has to provide a custom compare functor.
vermarajeev
3rd October 2006, 12:13
I guess that for Qt3 with QPtrList it might make a difference. Of course STL doesn't support dedicated lists for pointers, so to port the same behaviour to STL, one has to provide a custom compare functor.
Can you please visualize with an example??
Powered by vBulletin® Version 4.2.5 Copyright © 2023 vBulletin Solutions Inc. All rights reserved.