1

Given this how does the end() function added in C++ 11 know the end of the array.

1 Answer 1

4

I'm not sure I understand your question... it could be implemented like this maybe?

namespace std
{
    template<class T, size_t N>
    T *end(T (&arr)[N]) { return &arr[N]; }
}
Sign up to request clarification or add additional context in comments.

13 Comments

@Himanshu: The size of the array is known at compile time. The template basically extracts that information that the compiler already knew.
@user2485710: That is correct but how is it relevant to the question?
IIRC, in C++ this actually invokes UB due to dereferencing the past-the-end pointer of the array (inside the subscript). The safe way would be &arr[0] + N.
@user2485710: In all honestly I'm not understanding what you're trying to say. Maybe Jerry does?
@Mehrdad you're the one that has to provide a reference. The standard prefers to state guarantees, not non-guarantees. Asking someone to provide a standard reference for a non-guarantee is dishonest.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.