KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I use the following template to obtain a pointer pointing after the last element of an array: template <typename T, size_t n> T* end_of(T (&array)[n]) { return array + n; } Now I seem to remember that there was some problem with this approach, but I cannot remember what it was. I believe it had something to with the choice of the type parameters or function parameters, but I'm not sure. So just as a sanity check, do you see any problems with the above code? Small usage test: int test[] = {11, 19, 5, 17, 7, 3, 13, 2}; std::sort(test, end_of(test));
Tags (comma-separated)
Save Edits
Cancel