const version for foreach/opApply

Matthias Walter xammy at xammy.homelinux.net
Sat Jun 9 03:09:14 PDT 2012


On 2012-06-08 22:47, Era Scarecrow wrote:
> On Friday, 8 June 2012 at 16:33:28 UTC, Matthias Walter wrote:
>> Hi,
>>
>> trying to traverse the entries of a std.bitmanip.BitArray I stumbled
>> upon the following problem:
>>
>> In case I want to accept const(BitArray) objects, it shall look like
>> the following (maybe using "ref const(bool)" for the delegate
>> parameter?):
>>
>> int opApply(scope int delegate(bool) dg) const
> 
>>
>> Can one glue both things together into a single routine (using inout
>> magic or whatever)?
> 
>  I want to say you can't, because ref bool. If you ignore the reference,
> you don't need the non-const version (I think).
> 
>  I am currently working on BitArray updates, and it is const/immutable
> friendly according to as many tests as I could come up with for valid
> usage; This has taught me a lot on using templates, traits, constraints
> and how inout actually works. I haven't tried for a bit but I can try
> once more to send my code to GitHub, then you can give it a try.

First, thank you for your answer. I've already made some tiny
modifications in order to make BitArray work for my purposes:

https://github.com/xammy/phobos/commit/eb46d99217f2bf1e6d173964e2954248b08146d6

If you plan to create pull requests for your changes - please consider
my changes as well. When do you expect to finish, i.e., create a pull
request for phobos?


More information about the Digitalmars-d-learn mailing list