MyTinySTL icon indicating copy to clipboard operation
MyTinySTL copied to clipboard

functional.h 类模板 `identity` 实现模板参数错误?

Open LiuYuan-SHU opened this issue 1 year ago • 2 comments

请看代码, 此处实例化是否应当为:

template <class T> struct identity : public unarg_function<T, T> {
  const T &operator()(const T &x) const { return x; }
};

即将父类模板的第二个模板参数实例化为T而非bool

LiuYuan-SHU avatar Dec 11 '23 03:12 LiuYuan-SHU

已经收到您的邮件!!!

Adeshen avatar Dec 11 '23 03:12 Adeshen

我觉得它应该改成这样:

struct identity {
  template <class T>
  constexpr T &&operator()(T &&x) const noexcept { return (T&&)x; }
};

frederick-vs-ja avatar Jan 12 '24 11:01 frederick-vs-ja