Deduce return type via result_of, close #9631.

Signed-off-by: Kohei Takahashi <flast@flast.jp>