Vector End

Is it safe to assume that:
*(vector<TYPE>::end() - 1) == vector<TYPE>::back()
?
Last edited on
end() and back() are not static functions so you can't can't call it without an object. If you replace :: with . and vector<TYPE> with a vector object it is only safe if the vector is not empty.
closed account (Dy7SLyTq)
he wasnt calling them. he was showing the method and what scope they are in. while you are right, when you talk about a class method you want to say class_name::method. what if I said I like how optimized the at method is (just an example idk if its true) instead of list::at?
DSTCode: Not sure what you are trying to say but there is no std::list::at function.
closed account (Dy7SLyTq)
sorry im tired and it was the first container method that came to mind. can we pretend i said size instead? anyways... when you are asking a question or talking about a method you say class_name::method because, well something like above. you never would have known to correct me if i hadnt said list::at. it makes things clearer (ie no ones trying to call them like that)
I think it is clear what you mean when you write list::at even though list is not a class but a class template, but in the OP it is asked about actual code and it's not even obvious if it's the same object on the LHS and RHS.
closed account (Dy7SLyTq)
hes not asking about actual code hes asking will those two methods be the same
hes not asking about actual code hes asking will those two methods be the same

He's asking if the two expressions will be equivalent. Since the two expressions are illegal, the question makes no sense. When something makes no sense, one should ask for clarification from the OP rather than asserting that one knows what the OP meant regardless of alternate interpretations of said post.
@bmw

Is it safe to assume that:
*(vector<TYPE>::end() - 1) == vector<TYPE>::back()
?


It is safe provided that the vector is not empty. If the vector is empty neither back() no *( end() -1 ) are defined.
Yes DTSCode you are right, I am not talking about specific code, just a generalized question.

Thanks everyone.
Topic archived. No new replies allowed.