Creating a global instance of a special type seems reasonable to me. I also use global Dict's for this kind of thing.
Instead of inc_global, I might define Base.(:+)(w::wrapper,s) = w.x + s so you can just do `w += 1` :) If you find a better way, I would love to see it. PS: Minor point, but looks like you have a typo. Should be `const w = wrapper(0.0)` I think. No biggie. On Tuesday, June 14, 2016 at 8:41:40 AM UTC+8, Arch Robison wrote: > > Indeed the one-element vector case was what inspired my wrapper. I > created the wrapper to avoid the run-time bounds check on the vector, > though I suppose I could sprinkle @inbounds to eliminate it. > > On Mon, Jun 13, 2016 at 6:40 PM, Eric Forgy <[email protected] > <javascript:>> wrote: > >> Not sure if this is the best way (curious about 'Ref'), but you could >> also make x a 1-element vector: >> >> const x = [0] >> >> x[1] += 1 >> > >
