Propagating constness through function results

David Zhang straivers98 at gmail.com
Sun Sep 17 21:33:10 UTC 2017


On Sunday, 17 September 2017 at 21:18:08 UTC, David  Zhang wrote:
> Hi,
>
> I have a class `Image`, and I have a function called 
> `getSubImage(Rect bounds)`. What I can't figure out is how to 
> get the result of `getSubImage()` to take on the constness of 
> the backing image.
>
> ie.
>     //The Image class is really just a view over a buffer 
> that's managed elsewhere
>     const(Image).getSubImage(...) -> const(Image)
>
>     Image.getSubImage(...) -> Image
>
> I tried to do this with `inout`, but that requires that a 
> parameter in the function be `inout`. I don't suppose I could 
> somehow declare `this` to be inout?
>
> Thanks

I am aware that you can duplicate the method, but it seems a bit 
unwieldy and excessive.


More information about the Digitalmars-d-learn mailing list