Propagating constness through function results

David Zhang straivers98 at gmail.com
Sun Sep 17 21:18:08 UTC 2017


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


More information about the Digitalmars-d-learn mailing list