我正在探索透明操作符仿函数的MSVC实现(Visual Studio 2015),并注意到所有特化static_cast
所有内容:
// TEMPLATE STRUCT SPECIALIZATION less
template<>
struct less<void>
{ // transparent functor for operator<
typedef _Is_trans is_transparent;
template<class _Ty1,
class _Ty2>
_CONST_FUN auto operator()(_Ty1&& _Left, _Ty2&& _Right) const
-> decltype(static_cast<_Ty1&&>(_Left)
< static_cast<_Ty2&&>(_Right))
{ // transparently apply operator< to operands
return (static_cast<_Ty1&&>(_Left)
< static_cast<_Ty2&&>(_Right));
}
};
...为什么static_cast
_Right
到_Ty2&&
,当它已经是_Ty2&&
类型时?这似乎完全是多余的!