www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - BitArray oddities

reply "Adam S" <longestpants gmail.com> writes:
Playing around with BitArray I encountered the seemingly strange 
interface of

-------
bool[] b = [0, 1, 0];

BitArray a;
a.init(b);
-------

Is there any reason 'init' is used rather than using a 
constructor?

--------
bool[] b = [0, 1, 0];

BitArray a = BitArray(b);
--------

Seems a bit clearer. Regardless, the current approach seems to 
create problems when used with std.parallelism. Specifically the 
following fails to compile:

--------
BitArray[] arr;
arr ~= BitArray();

taskPool.amap!((BitArray a) {/*do something*/})(arr);
--------
Fails with:
     Error: function std.bitmanip.BitArray.init (bool[] ba) is not 
callable using argument types ()

Can anyone explain the reason for this setup?
Jan 09 2014
parent "Adam D. Ruppe" <destructionator gmail.com> writes:
On Friday, 10 January 2014 at 02:08:21 UTC, Adam S wrote:
 Can anyone explain the reason for this setup?
BitArray was mostly written back in the D1 days, before structs were allowed to have constructors. It got partially updated, but the majority of its code is still an old style. I recently talked about this on SO too:
Jan 09 2014