I'm playing with C++11 move constructors but they don't seem
to be working with clang 3.3svn.
With this:
struct X {
char *data;
X(char const *p) { int n = strlen (p); data = (char*)malloc(n+1); strcpy
(data,p); }
X(X &&a) : data(a.data) { printf("Move\n"); }
X(X const &a) { int n = strlen (a.data); data = (char*)malloc(n+1); strcpy
(data, a.data); printf("Copy\n"); }
X operator + (X a) {
int n = strlen (data);
int m = strlen (a.data);
char *out = (char*)malloc (n + m + 1);
strcpy (out,data);
strcpy (out+n, a.data);
return X(out);
}
};
int main() {
X x = X("Hello World");
printf ("Result = %s\n",x.data);
X b = x + X(" what ")+ x + x + x + x;
printf ("Result = %s\n",b.data);
return 0;
}
I get a whole heap of copies.
If I use const & in operator + I get none.
It seems wrong. Pass by value should be invoking
the move constructor when the argument is an rvalue.
--
john skaller
[email protected]
http://felix-lang.org
------------------------------------------------------------------------------
Want excitement?
Manually upgrade your production database.
When you want reliability, choose Perforce
Perforce version control. Predictably reliable.
http://pubads.g.doubleclick.net/gampad/clk?id=157508191&iu=/4140/ostg.clktrk
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language