const version for foreach/opApply

Era Scarecrow rtcvb32 at yahoo.com
Fri Jun 8 13:47:09 PDT 2012


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.


More information about the Digitalmars-d-learn mailing list