Skip to main content
7 events
when toggle format what by license comment
Oct 12, 2015 at 14:26 comment added Nir Friedman Alias does not require a shared/weak ptr, it will just have a raw pointer. If this seems scary, then stop and think of iterators. This is part of the super lightweight comment I made, raw pointers are much lighter than shared/weak. Probably worth looking at array_view, but my perspective is shaped by looking at Alias/ConstAlias as iterators. Aside from the fact that you happen to need two of them, iterators are exactly lightweight non-owning views, with vector as the owner. All free functions in the STL take iterators rather than containers directly.
Oct 12, 2015 at 14:20 comment added Emily L. Yes, it's shared. However an Alias will require a shared or weak ptr too. Otherwise it cannot access the image data. At any rate we both seem to be thinking of Alias/Image as a view and this is quire similar to the N3851 array_view proposal. I might glean at that...
Oct 12, 2015 at 14:15 comment added Nir Friedman It's a smart pointer, but it sounds like it's a shared pointer, no? I discuss this issue as well in my post. This ownership model is much more confusing, you can pass around Images and end up with entities owning Images that alias each other, which results in action at a distance. In contrast, {Const,}Alias is always short lived. I don't think there is much real code duplication, anything that is more than a one liner can be factored out into an implementation function. So it's really just the duplication of writing out the interface. Annoying, but better than a needless inheritance hierarchy.
Oct 12, 2015 at 14:05 comment added Emily L. Okay, so if I got this right. You're supposing I do not use inheritance but instead provide implicit conversion operator and live with the code duplication for the common methods? Also, although I didn't mention it explicitly but Buffer is a smart pointer type so my Image is also "thin".
Oct 12, 2015 at 13:21 comment added Nir Friedman Yes, but because the Alias is ultra light weight, you can write a trivial implicit conversion. No need to mess around with inheritance. Also, it seems like my design is different from yours, your Image owns Buffer seemingly, and Buffer is not for public consumption. My Alias is not owning, and Image is used publicly.
Oct 12, 2015 at 7:16 comment added Emily L. But then Alias must be convertible to/or inherit from ConstAlias. Because functions that accept a ConstAlias must also accept a non-const alias, and we're back at the original question. Note, that your proposed design is pretty much what I have in the OP just that what you call Image, I call Buffer, and what you call Alias, I call Image. Note that it is also required that you can take sub-images of a sub-image, I.e. Alias must support the alias() function.
Oct 12, 2015 at 3:08 history answered Nir Friedman CC BY-SA 3.0