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

16.6 实现begin(), end() #95

Closed
Yuan-Hang opened this issue Nov 24, 2016 · 1 comment
Closed

16.6 实现begin(), end() #95

Yuan-Hang opened this issue Nov 24, 2016 · 1 comment

Comments

@Yuan-Hang
Copy link

Yuan-Hang commented Nov 24, 2016

应该这样实现才行:

template <typename T, size_t N>
inline T* _begin(T (&a)[N]) {
  // cout << "begin" << endl;
  return a;
}
template <typename T, size_t N>
inline const T* _begin(const T (&a)[N]) {
  // cout << "cbegin" << endl;
  return a;
}

template <typename T, size_t N>
inline T* _end(T (&a)[N]) {
  // cout << "end" << endl;
  return a + N;
}

template <typename T, size_t N>
inline const T* _end(const T (&a)[N]) {
  // cout << "cend" << endl;
  return a + N;
}
@pezy
Copy link
Owner

pezy commented Apr 4, 2017

const 在这里有点多余,在这里,T 涵盖了 const T

见:http://stackoverflow.com/questions/9679116/is-there-any-difference-between-t-and-const-t-in-template-parameter

@pezy pezy added the wontfix label Apr 4, 2017
@pezy pezy closed this as completed Apr 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants