I apologize in advance for the off-topic nature of this
posting, but I thought I'd ask this of the list I know
the best first:

Are any of our readers familiar with use of the various
containers in the C++ Standard Template Library (STL)?
I have a question about the use of one STL container,
the priority queue.

Here's the problem: say I have a class MyClass, and wish
to store a bunch of pointers to instances of MyClass in
a priority queue. I want the pointers to be ordered
based on the relative values of another data element,
call it ThisDat (which could be either int or float)
stored inside the MyClass datum each pointer points to.
This means I need to define a custom compare function
and tell the compiler to use it (rather than default < )
when ordering the queue. So far, so good. But, what is
the syntax for implementing this custom compare? (Let's
call it MyComp). In other words, what should go in place
of the ?? in the following outline:

class MyClass
{
    public:
        int ThisDat;
etc...
};

Stroustrup's C++ special edition suggests a syntax like

priority_queue<MyClass*, vector<MyClass*>??, MyComp??>;

but doesn't explain why one needs the vector<> middle
term (i.e. why a vector, since the priority queue isn't
required to use a vector container type?)

And, should the definition of MyComp be something like
the following?

bool MyComp(MyClass a, MyClass b)
{
    return(a.ThisDat < b.ThisDat);
}

Please resoond by *private* e-mail & thanks in advance.
I now return this mailing list to its regular Mersenne-
oriented programming.

-Ernst


_________________________________________________________________________
Unsubscribe & list info -- http://www.scruz.net/~luke/signup.htm
Mersenne Prime FAQ      -- http://www.exu.ilstu.edu/mersenne/faq-mers.txt

Reply via email to