how to correctly find out the return type of a lambda

后端 未结 3 1896
闹比i
闹比i 2020-12-11 22:04

basically how to make following code compile?

I know it failed because compiler was trying to evaluate something like ([](int &i){})(0) but how to s

3条回答
  •  爱一瞬间的悲伤
    2020-12-11 22:30

    Two ways. First:

    using TResult = decltype(f(_e));
    

    or second:

    using TResult = typename std::result_of::type;
    

    Your code implicity says that the TElement is a temprary/rvalue. The & above makes them lvalues.

提交回复
热议问题