|
-
June 30th, 2010, 07:04 AM
#11
Re: CArray vs. std::vector
1) Well, you also said that mixing MFC and STL was a "headache".
That might have been true a long time agao (pre version 5), but
since version 5 (~1997 ?) there are no problems mixing the two.
2) The problem with the MFC containers is that they do no even have
a consistent interface for looping thru the elements. You have to loop
thru a CList in a different way than thru a CArray. This means you need
to write duplicate code for doing such simple tasks as finding if an
element is in the container, or finding the largest element.
3) how many times has something like this been seen on the other board ?
Code:
class A
{
CArray< .... >;
// other
};
class B
{
CArray<A,...>
};
And they want to know whay it will not compile.
4) using qsort on a container of CString is technically undefined,
but since MS does it, I'll let it slide. But using qsort on other
non-POD elements still should not be done. Also, how are you
going to sort a CList ?
5) Here is a sample code ... feel free to publish your results
(also, not cheating by calling SetSize() or simuilar functions ....
remember my original post specifically stated the case where
you do not know how many elements before hand)
Code:
#include "stdafx.h"
#include <iostream>
#include <vector>
#include <ctime>
#include <afxtempl.h>
using namespace std;
int main()
{
int n;
cout << "enter number of elements > ";
cin >> n;
clock_t start , finish;
CString s("Hello World");
start = clock();
/*
vector<CString> v;
for (int i=0; i<n; ++i)
{
v.push_back(s);
}
*/
CArray<CString,const CString &> v;
for (int i=0; i<n; ++i)
{
v.Add(s);
}
finish = clock();
cout << "number of ticks = " << finish - start << "\n";
return 0;
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|