Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
LiuYuan-SHU opened this issue Dec 11, 2023 · 2 comments
Open

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

LiuYuan-SHU opened this issue Dec 11, 2023 · 2 comments

Comments

@LiuYuan-SHU
Copy link

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

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

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

@Adeshen
Copy link

Adeshen commented Dec 11, 2023 via email

@frederick-vs-ja
Copy link
Contributor

我觉得它应该改成这样:

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants