Deterministic life-time storage type
Michel Fortin
michel.fortin at michelf.com
Sun Apr 22 04:12:03 PDT 2012
On 2012-04-22 06:41:46 +0000, travert at phare.normalesup.org (Christophe
Travert) said:
> Michel Fortin , dans le message (digitalmars.D:164824), a écrit :
>> So with your system, how do you write the swap function?
>
> I've thought about that.
> The scope(label) is the key.
>
> void T swap(T)(scope T a, scope(a) T b)
> {
> scope(a) tmp = a;
> a = b;
> b = tmp;
> }
>
> scope(inout) would also do the trick, since it is implicitely shared
> between parameters and return values.
Your proposal is very similar to some things that were discussed in
2008 when escape analysis became the topic of the day on this
newsgroup. There were two problems for adoption: it makes writing
functions difficult (because you have to add all that scoping thing to
your mental model) and implementing new type modifiers is a major
undertaking that didn't fit with the schedule. While the second problem
might disappear given enough time, the first one is a hurdle.
You might find this a good read:
<http://www.digitalmars.com/d/archives/digitalmars/D/Escape_analysis_78791.html>
--
Michel Fortin
michel.fortin at michelf.com
http://michelf.com/
More information about the Digitalmars-d
mailing list