Provide comparator to a class

C

Christopher

How can I ... let's see if I can word this right... provide a
comparator to be determined by the client of my library, to a class in
my library for the use of ordering objects in a container?

I want to modify this source, to allow the user of the class to give
me thier own comparator at construction time:

#ifndef RENDERQUEUE_H
#define RENDERQUEUE_H

// EngineX Includes
#include "IRenderable.h"

// Standard Includes
#include <vector>

//------------------------------------------------------------------------------
class RenderQueue
{
public:

/**
*
**/
RenderQueue();

/**
*
**/
~RenderQueue();

/**
* Inserts a renderable object into the render queue
**/
void Insert(IRenderable * object);

/**
* Removes a renderable object off the queue
**/
void Remove(IRenderable * object);

protected:

/**
* Comparator
**/
struct Compare
{
bool operator () (const IRenderable * lhs, const IRenderable *
rhs);
};

/**
* Priotity Queue container
**/
typedef std::vector<IRenderable *> Queue;
Queue m_queue;

private:

};

#endif // RENDERQUEUE_H
 
M

Michael Doubez

How can I ... let's see if I can word this right... provide a
comparator to be determined by the client of my library, to a class in
my library for the use of ordering objects in a container?

If you want to do it at compile time can make your class a template,
use a template parameter as comparison operator ( plus a parameter,
see std::set for example).

Otherwise, define an interface functore and require the overloading of
member function bool operator()(lhs,rhd)const.
I want to modify this source, to allow the user of the class to give
me thier own comparator at construction time:
[snip]
 

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,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top