On 10/9/2017 8:04 AM, Per Nordlöw wrote:
I'm trying to figure out how to make my manually written containers have
scope-aware element(s)-accessing functions. I've come up with 5 different
situations as follows
I find it is hopeless to explain how this works with refs, arrays, member
functions, etc. It's much simpler to rewrite anything you're unsure of as using
nothing but pointers and free functions. (After all, the compiler lowers all
that reference stuff to pointers and free functions anyway.)
Making it explicit where all the pointers and parameters are makes it a LOT
easier to reason about how dip1000 works.
For example, replace:
int[]
a[0]
with:
int*
*a
Get rid of the templates, too. Replace T with int. Get rid of any of the layers
of confusing complexity. Think "what does the compiler lower this construct to"
and do that.
Once it is clear how the pointers works, then start adding the complexity back
in.