Quote:
Originally Posted by
VelvetTLeopard
I just don't see why anyone would add an include, in this case #include<map>, to store a value because that single include file is going to add more lines than necessary.
Are you going to attempt to write a C++ program without using the standard library, which means you must #include files?
Quote:
You have a call to BigFunction()
Which I am using just as an example
Quote:
two calls to insert(), and two calls to make_pair().
Those are done to initialize the map. Once the map is initialized, there is no need for further initialization. The new version of C++ has nicer initialization syntax -- would that have changed your take on the code if I used C++ 11? What you're concentrating on is moot, as again, it is there to initialize the map, nothing else.
Quote:
You are passing variables by value in all five of the functions in your code.
Where are variables passed by value? Can you point out where values are passed by value?
Quote:
This means you are making copies of all the argument variables passed to them. Since you are merely displaying the data in these functions and not actually changing them, you really should pass them by reference, so they can not be changed.
I wish I knew what you are referring to.
Quote:
And as for judging optimization by sight, I can't do it yet, but people experienced can.
I guess 20+ years of doing C++ isn't experience enough. OK.
The code I posted is a sample of how a map operates. Nothing more, nothing less. It's there so you can see the syntax and the higher-level constructs that can be used to make the program maintainable.
Quote:
All it takes is knowing the intricacies of thee variables and other parts of the code, how the lexicon and parser work, how the compiler works and a bit of Big O use.
You are talking about bare algorithms. I am talking about looking at C++ higher extractions and classes such as map, vector, bitset, functors, etc. and attempting to judge "Big O" based on that information. It has been proven time and time again that you cannot take C++ code using these constructs and firmly state what is fast or slow unless you run the program and time it.
Quote:
Yes, you can judge the "size" of a function by looking at it. You simply do the math of how often the function is called as well as what the functions does. Those two calls to make_pair() are creating in memory four more variable values plus the two they used to copy. That means your code snippet has allocated memory for six variables and that is for each time the snippet runs.
OK, what about this:
Code:
int main()
{
BoolMap myMap;
// Initialize the map
myMap[true] = "White";
myMap[false] = "Black";
}
The question -- is this faster than using make_pair()?
Regards,
Paul McKenzie