D locking strategies

Andrea Fontana nospam at example.com
Fri Mar 15 06:39:31 PDT 2013


On Friday, 15 March 2013 at 02:20:01 UTC, estew wrote:
> Ok, I did a bit more reading of TDPL and decided to go with the 
> following pattern:
>
> synchronized class A{
>      private string[] _values;
>      void setValue(size_t i, string val)  {_values[i] = val;}
>      string getValue(size_t i) const  {return _values[i];}
>  }
>
> Works fine, my problem solved :) Again, D makes it so easy!
>
> Thanks,
> Stewart

Why don't you implement opIndex for class A?

http://dlang.org/operatoroverloading.html#Array


More information about the Digitalmars-d-learn mailing list