>isn't it sometimes a good idea to make your own clases insted of using the predefined?
Of course. The standard classes cannot solve all of your problems, but they should be the first thing you turn to for a solution because you don't have to worry about debugging them, you only have to concentrate on using them, which is far more productive.
Really? I thought that problem-solving was the fun part
If it turns out that you need a real speed gain and the standard classes don't cut it then you can write your own. Of course, the STL is written with speed in mind, so a lot of the time homegrown code with equivalent features would be hard pressed just to match the speed of the STL.
Code:
int main() {
char *winner = "neither";
time_t start, stop, finish, stl_finish, amount = 0;
int i;
start = clock();
do{
String a = "A rose is a rose is a rose is a rose is a rose is a rose is a rose is a rose is a rose is a rose is a rose is a rose is a rose is a rose...";
//a.FindAndReplace("rose", "tulip");
}while(i++ < 1000000);
stop = clock();
finish = (stop-start)/1000;
i = 0;
start = clock();
do{
string b = "A rose is a rose is a rose is a rose is a rose is a rose is a rose is a rose is a rose is a rose is a rose is a rose is a rose is a rose...";
//b.FindAndReplace("rose", "tulip");
}while(i++ < 1000000);
stop = clock();
stl_finish = (stop-start)/1000;
if(stl_finish > finish)
winner = "Sebastian's",
amount = stl_finish - finish;
else
if(stl_finish < finish)
winner = "the stl",
amount = finish - stl_finish;
/*
...on my machine, this prints:
"The winner is Sebastian's library, by 3 whole seconds."
*/
printf("The winner is %s library, by %i whole seconds.\n", winner, amount);
getch();
return 0;
}
That was just assignment. Had I been able to find the string::find_and_replace() function, the results might've been even more devastating!
String please = "The best option is to solve the problem in the simplest way possible, then improve performance only if you really need to."
please.FindAndReplace("only if you really need to.", "as soon as you can, especially if you're using the STL!!");
-Sebastian