Fixed result type deduction to work with templates on GCC (using function ptr and Boost.ScopeExit type tagging/wrapping/etc).