On 8 April 2013 17:35, Jacob Carlborg <d...@me.com> wrote: > On 2013-04-08 06:30, Manu wrote: > > I wonder if UDA's could be leveraged to implement this in a library? >> UDA's can not permute the type, so I guess it's impossible to implement >> something like @noalloc that behaves like @nothrow in a library... >> I wonder what it would take, it would be generally interesting to move >> some of the built-in attributes to UDA's if the system is rich enough to >> express it. >> >> As a side though though, the information about whether a function can >> allocate could be known implicitly by the compiler if it chose to track >> that detail. I wonder if functions could gain a constant property so you >> can assert on that detail in your own code? >> ie: >> >> void myFunction() >> { >> // does stuff... >> } >> >> >> { >> // ...code that i expect not to allocate... >> >> static assert(!myFunction.**canAllocate); >> >> myFunction(); >> } >> >> This way, I know for sure my code is good, and if I modify the body of >> myFunction at some later time (or one of its sub-calls is modified), for >> instance, to make an allocating library call, then i'll know about it >> the moment I make the change. >> > > Scott Meyers had a talk about what he called red code/green code. It was > supposed to statically enforce that green code cannot call red code. Then > what is green code is completely up to you, if it's memory safe, thread > safe, GC free or similar. > > I don't remember the conclusion and what could be implemented like this, > but here's the talk: > > http://www.google.com/url?sa=**t&rct=j&q=scott%20meyers%** > 20red%20green%20code&source=**web&cd=1&cad=rja&ved=** > 0CCsQtwIwAA&url=http%3A%2F%**2Fwww.youtube.com%2Fwatch%3Fv%** > 3DJfu9Kc1D-gQ&ei=**fXJiUfC3FuSB4gS41IHADQ&usg=**AFQjCNGtKwLcr2jNjsC4RJ0_** > 5k8WmAFzTw&bvm=bv.44770516,d.**bGE<http://www.google.com/url?sa=t&rct=j&q=scott%20meyers%20red%20green%20code&source=web&cd=1&cad=rja&ved=0CCsQtwIwAA&url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DJfu9Kc1D-gQ&ei=fXJiUfC3FuSB4gS41IHADQ&usg=AFQjCNGtKwLcr2jNjsC4RJ0_5k8WmAFzTw&bvm=bv.44770516,d.bGE>
That sounds awesome. I'll schedule it for later on! :P