Hi Timothy,
I think it should be possible -- or I wouldn't be suggesting it :)
func poolPush() {}
func poolPop() {}
public func autoreleasepool<Result>(@noescape code: () throws ->
Result) rethrows -> Result {
poolPush()
defer { poolPop() }
return try code()
}
Dmitri
···
On Sun, Mar 20, 2016 at 9:32 PM, Timothy Wood via swift-evolution <swift-evolution@swift.org> wrote:
In preparation for writing a proposal, I wanted to solicit any feedback and general level of interest on addressing SR-842, which proposes modifying ObjectiveC.autoreleasepool to allow a potentially `throw`ing body via a `rethrows` annotation. I have a branch with the very simple change applied and a test. However, Dmitri Gribenko pointed out that it would be even better if the signature was amended to allow for a generic return type:
public func autoreleasepool<Result>(@noescape code: () throws -> Result) rethrows -> Result
It isn’t clear to me whether it is possible for a wrapper to be written that adds rethrow, since the function needs to compile under the assumption that the passed block does not throw. So, something like this doesn’t actually compile.
--
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr@gmail.com>*/