| | |
comparing a number to an undefined number of values
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2008
Posts: 36
Reputation:
Solved Threads: 1
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
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)
class Mother { public: Mother(){} ~Mother(){} template<int msg> inline void HandleMessage(){}; template<> inline void HandleMessage<10>() { std::cout<<"It works!\n"; } };
All i've got is a slice of pi
•
•
Join Date: Jan 2008
Posts: 3,819
Reputation:
Solved Threads: 501
•
•
•
•
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)
class Mother { public: Mother(){} ~Mother(){} template<int msg> inline void HandleMessage(){}; template<> inline void HandleMessage<10>() { std::cout<<"It works!\n"; } };
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.
•
•
Join Date: Sep 2008
Posts: 36
Reputation:
Solved Threads: 1
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.
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.
All i've got is a slice of pi
•
•
•
•
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.
I give up! 1) What word becomes shorter if you add a letter to it? [ Solved by : niek_e ] 2) What does this sequence equal to : (.5u - .5a)(.5u-.5b)(.5u-.5c) ... 3) What is the 123456789 prime numer? Ask4Answer
•
•
Join Date: Sep 2008
Posts: 36
Reputation:
Solved Threads: 1
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
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
All i've got is a slice of pi
![]() |
Similar Threads
- how to find number of integers in a number (C++)
- Assembly couting number of 1s in binary number (Assembly)
- convert integer number to float number (PHP)
- count number of ones and zeroes in a number (C)
- number of times each number in array occurs? (C)
- Finding the number of digits in a number (C++)
- Number of times a number appears in an array (C++)
Other Threads in the C++ Forum
- Previous Thread: getaddrinfo() not declared in this scope
- Next Thread: Debug vs. Release
| Thread Tools | Search this Thread |
api array arrays based beginner binary c++ c/c++ calculator char char* class classes code compile compiler console conversion count delete deploy desktop directshow dll download dynamic dynamiccharacterarray encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory news number numbertoword output parameter pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct temperature template templates test text text-file tree unix url variable vector video visual visualstudio win32 windows winsock wordfrequency wxwidgets






