473,508 Members | 2,330 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

template function compareLess

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

Sep 22 '05 #1
2 1270
everything is possible,but there must be operator=,or operator< in
your T classes

Sep 22 '05 #2

"Gr*****@nospam.com" <Gr**********@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
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 <functional>.


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::operator () is a good candidate for inlining the
instantiation would cause code bloat because ideally not a single function
is generated with however many instantiations.


thanks

G


No worries!
Ben
Sep 22 '05 #3

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

Similar topics

4
2333
by: Thomi Richards | last post by:
Hi, I'm trying to create a simple stack class using C++ and templates. Everything works well and good if I amke the class totally inline. However, as soon as I try to seperate the class into a...
7
2117
by: Lionel B | last post by:
Greetings. The following code compiles ok and does what I'd expect it to do: ---------- START CODE ---------- // test.cpp
4
1747
by: Grahamo | last post by:
Hi I'm working with deployed code and am looking for ways to optimise it and clean up memory leaks etc. I'm working with a template ContainerOfPointers, which is exactly that. It has methods...
9
2743
by: Marek Vondrak | last post by:
Hello. I have written the following program and am curious why it prints "1" "2". What are the exact effects of explicitly providing function template parameters at the call? Is the second...
7
9430
by: quarup | last post by:
I want to specialize a template function that lives inside a class, but am getting a compile error in VS.net 2003. Here's my code: template <class T> class A { public: template <class U> void...
5
2251
by: StephQ | last post by:
This is from a thread that I posted on another forum some days ago. I didn't get any response, so I'm proposing it in this ng in hope of better luck :) The standard explanation is that pointer...
8
5302
by: Jess | last post by:
Hi, I have a template function that triggered some compiler error. The abridged version of the class and function is: #include<memory> using namespace std; template <class T>
2
2579
by: Alan | last post by:
Does a template class declaration, like template <class T> have to come immediately prior to the declaration of the function, e.g., T do_something (T something) { . . . } that uses it?
8
284
by: William Xu | last post by:
Compiling: template <class T = int> T foo(const T& t) {} int main(int argc, char *argv) {} gcc complains:
0
7233
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7135
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
7342
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
7505
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...
1
5060
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...
0
4729
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3215
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1570
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
440
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.