On 02/01/2014 11:05 PM, Adam D. Ruppe wrote:
A library solution to this exists already: Widget wn = fetchWidget(); if(auto w = wn.checkNull) { // w implicitly converts to NotNull!Widget } I've had some difficulty in const correctness with my implementation... but const correct is an entirely separate issue anyway. It isn't quite the same as if(w) but meh, does that matter? The point of the static check is to make you think about it, and that's achieved here.
The following illustrates what's not achieved here: if(auto w = wn.checkNull){ // ... }else w.foo();