SFINAE check for operator+=

前端 未结 4 581
无人共我
无人共我 2021-01-01 21:07

I\'m trying to eliminate an overload from an overload set if operator+= is missing.

I know how to check if T+T is legal :

t         


        
4条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-01 21:42

    I would write the second form as:

    template
    auto foo(T a, T b, ...) -> decltype( a+=b, void() )
    {
      a += b;
    }
    

    The deduced type for decltype(a+=b, void()) would be just void if the expression a+=b is valid, else it would result in SFINAE.

    Well, even in the first form, I would use the trailing-return type approach.

提交回复
热议问题