You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, you can write vec + elem to get back a new Vector that consists of all the elements of vec with elem appended to the. end. However, the reverse elem + vec does not compile. We should consider adding an overload of operator+ that addresses this.
The text was updated successfully, but these errors were encountered:
I agree that a smaller interface is a nice thing to have.
There's a nice parallel between the overloads for Vector<T> and for std::string. You can write str + ch to form a new string with a character at the end, and you can write ch + str to form a new string with a character added at the beginning. I had some students ask me a while back why the same doesn't work for Vector. This particularly came up with some recursion warm-up exercises where code for strings looks really different than code for Vectors. An example:
Currently, you can write
vec + elem
to get back a newVector
that consists of all the elements ofvec
withelem
appended to the. end. However, the reverseelem + vec
does not compile. We should consider adding an overload ofoperator+
that addresses this.The text was updated successfully, but these errors were encountered: