template function compareLess

G

Grahamo

Hi,

I've written a custom Iterator and managed to get things working ok.
I'm looking to see if I can reduce the amount of template instantiation
in my code however (borland gives an out of memory when compiling the
whole app).


template <class T >
class compareGreater // (T p1, T p2)
{

bool operator()( T& p1, T& p2)
{

// does comparison by calling operator< on types T
}
};


I have many types T in this codebase and I would like, if possible, to
prevent a new compareGreater<T> being instantiated for all types.
Instead I'd like all containers to use a single generic, "generic"
compareGreater routine. Is that possible?


thanks

G
 
B

benben

Hi,

I've written a custom Iterator and managed to get things working ok.
I'm looking to see if I can reduce the amount of template instantiation
in my code however (borland gives an out of memory when compiling the
whole app).

Ok, but then, where's your code to calculate the amount of template
instantiation?
template <class T >
class compareGreater // (T p1, T p2)
{

bool operator()( T& p1, T& p2)
{

// does comparison by calling operator< on types T
}
};

This looks like std::greater in said:
I have many types T in this codebase and I would like, if possible, to
prevent a new compareGreater<T> being instantiated for all types.
Instead I'd like all containers to use a single generic, "generic"
compareGreater routine. Is that possible?

Why would you want to prevent a new compareGreater<T> being instantiated for
each distinct T? If that's ever possible you would be able to write it
without using template (you should try.) By the way since
compareGreater::eek:perator () is a good candidate for inlining the
instantiation would cause code bloat because ideally not a single function
is generated with however many instantiations.

No worries!
Ben
 

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
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top