943,551 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 425
  • C++ RSS
Sep 19th, 2009
0

comparing a number to an undefined number of values

Expand Post »
Hi I have a problem, I hope you can help me with.

I have a number, which I need to compare to some values.

I do not wish to go through all the values, and compare them individually, as I there are too many for it to be efficient.

Neither do I want to create an array with the size of the range of numbers, as it can anything from 0 UINT_MAX

So I am hoping that you might have a better solution.

Here is an example of what I have tried, but didn't work,
because I get the values dynamicly

CPP Syntax (Toggle Plain Text)
  1. class Mother
  2. {
  3. public:
  4. Mother(){}
  5. ~Mother(){}
  6.  
  7. template<int msg> inline void HandleMessage(){};
  8.  
  9. template<> inline void HandleMessage<10>()
  10. {
  11. std::cout<<"It works!\n";
  12. }
  13. };
Similar Threads
Reputation Points: 12
Solved Threads: 1
Light Poster
mostermand is offline Offline
36 posts
since Sep 2008
Sep 19th, 2009
0

Re: comparing a number to an undefined number of values

Click to Expand / Collapse  Quote originally posted by mostermand ...
Hi I have a problem, I hope you can help me with.

I have a number, which I need to compare to some values.

I do not wish to go through all the values, and compare them individually, as I there are too many for it to be efficient.

Neither do I want to create an array with the size of the range of numbers, as it can anything from 0 UINT_MAX

So I am hoping that you might have a better solution.

Here is an example of what I have tried, but didn't work,
because I get the values dynamicly

CPP Syntax (Toggle Plain Text)
  1. class Mother
  2. {
  3. public:
  4. Mother(){}
  5. ~Mother(){}
  6.  
  7. template<int msg> inline void HandleMessage(){};
  8.  
  9. template<> inline void HandleMessage<10>()
  10. {
  11. std::cout<<"It works!\n";
  12. }
  13. };

I think you'll have to be a bit more specific about what you're after, what needs to be compared, stuff like that. I don't know what to make of the code snippet, as it has no comparisons. off the top of my head, if you have ordered data, use a binary search so you don't have to compare every element, but again, without having any idea what kind of data you have or what kind of comparisons you need to make, it's hard to speculate.
Featured Poster
Reputation Points: 2614
Solved Threads: 687
Posting Expert
VernonDozier is offline Offline
5,371 posts
since Jan 2008
Sep 19th, 2009
0

Re: comparing a number to an undefined number of values

Well it is an integer, compared to a list of integers.
Reputation Points: 12
Solved Threads: 1
Light Poster
mostermand is offline Offline
36 posts
since Sep 2008
Sep 19th, 2009
0

Re: comparing a number to an undefined number of values

Click to Expand / Collapse  Quote originally posted by mostermand ...
Well it is an integer, compared to a list of integers.
Any reason a binary search won't work?
Featured Poster
Reputation Points: 2614
Solved Threads: 687
Posting Expert
VernonDozier is offline Offline
5,371 posts
since Jan 2008
Sep 19th, 2009
0

Re: comparing a number to an undefined number of values

Too time consuming. I would rather not do it at all then

And about the code snippet, if I create an instance of Mother,
and call HandleMessage<10> it would print "It works!\n".

But if I call it with any other value it would do nothing,
the reason I am not doing this, is that I don't know the values at compile time.
Reputation Points: 12
Solved Threads: 1
Light Poster
mostermand is offline Offline
36 posts
since Sep 2008
Sep 19th, 2009
0

Re: comparing a number to an undefined number of values

Click to Expand / Collapse  Quote originally posted by mostermand ...
Too time consuming. I would rather not do it at all then

And about the code snippet, if I create an instance of Mother,
and call HandleMessage<10> it would print "It works!\n".

But if I call it with any other value it would do nothing,
the reason I am not doing this, is that I don't know the values at compile time.
Care to give a little more background?
Reputation Points: 840
Solved Threads: 594
Senior Poster
firstPerson is offline Offline
3,862 posts
since Dec 2008
Sep 19th, 2009
0

Re: comparing a number to an undefined number of values

Ok I am building a GUI Framework, where there is a Widget class,
which can both have mother widgets and be a mother widget.

When some event happens, the widget receives a message, in the form of an integer value(win32).
I want the widgets to be able to say to their children "I want to know when this happens", and then the mother widget's mother to be able do the same.

The alternative to this subscribe behavior, is to send some of the messages to the widget's mother
Reputation Points: 12
Solved Threads: 1
Light Poster
mostermand is offline Offline
36 posts
since Sep 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: getaddrinfo() not declared in this scope
Next Thread in C++ Forum Timeline: Debug vs. Release





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC