Share this Question
P: n/a

Alex Vinokur wrote: Why is not defined operator+ for vector?
What would it mean?
For instance, vector<T> v1, v2, v3; T a;
v1=v2+a;
Does this make v1 the concatenation of v2 and a, or the result of adding
a to each element of v2?
v1=v2+v3;
Does this add each element of v2 to the corresponding element from v3,
or make v1 the concatenation of v2 and v3?  
P: n/a

"Jeff Schwab" <je******@comcast.net> wrote in message news:6q********************@comcast.com... Alex Vinokur wrote: Why is not defined operator+ for vector? What would it mean?
For instance, vector<T> v1, v2, v3; T a;
v1=v2+a;
Does this make v1 the concatenation of v2 and a, or the result of adding a to each element of v2?
Concatenation of v2 and a. v1=v2+v3;
Does this add each element of v2 to the corresponding element from v3, or make v1 the concatenation of v2 and v3?
Concatenation of v2 and v3.

Alex Vinokur
mailto:al****@connect.to http://mathforum.org/library/view/10978.html  
P: n/a

> Why is not defined operator+ for vector? For instance, vector<T> v1, v2, v3; T a;
v1=v2+a; v1=v2+v3;
Too many operators make code less readable. If operator's meaning is not
obvious in context of the operation it performs, it's better to replace it
with named function. In case of standard library containers these functions
were named push_back and insert, which IMO better describes append
operations than operator +.
// v1 = v2 + a becomes:
v1 = v2;
v2.push_back(a);
// v1 = v2 + v3 becomes:
v1 = v2;
v1.insert(v1.end(), v3.begin(), v3.end());
cheers,
Marcin  
P: n/a

Alex Vinokur wrote: "Jeff Schwab" <je******@comcast.net> wrote in message news:6q********************@comcast.com...
Alex Vinokur wrote:
Why is not defined operator+ for vector?
....v1=v2+a; Concatenation of v2 and a.
....v1=v2+v3;
Concatenation of v2 and v3.
This behavior differs from the traditional, mathematical meaning of
adding two vectors. Neither concatenation, nor the mathematical meaning
are "wrong." Since there is no single, obvious meaning of operator+ for
vectors, why should any one definition be part of the standard library?
It can be overloaded easily in client code.  
P: n/a

Alex Vinokur 20040519 : "Jeff Schwab" <je******@comcast.net> wrote in message news:6q********************@comcast.com... Alex Vinokur wrote: Why is not defined operator+ for vector?
What would it mean?
For instance, vector<T> v1, v2, v3; T a;
v1=v2+a;
Does this make v1 the concatenation of v2 and a, or the result of adding a to each element of v2? Concatenation of v2 and a.
I would have said it adds a to every element of v2 v1=v2+v3;
Does this add each element of v2 to the corresponding element from v3, or make v1 the concatenation of v2 and v3?
Concatenation of v2 and v3.
I would have said it adds v2 and v3 element by element.
So you see a good reason (among others) why that operator is
*not* defined...
ciao
Walter  
P: n/a

Jeff Schwab wrote: Alex Vinokur wrote: Why is not defined operator+ for vector? What would it mean?
This is a weak argument. There are plenty of methods/operators that are far
from intuitive.
Take vector::empty(), for example.
Without prior (stl) knowledge, there is no way to know what this means: does it
test for an empty condition or empty the contents of the vector? For instance, vector<T> v1, v2, v3; T a;
v1=v2+a;
Does this make v1 the concatenation of v2 and a, or the result of adding a to each element of v2?
v1=v2+v3;
Does this add each element of v2 to the corresponding element from v3, or make v1 the concatenation of v2 and v3?  
P: n/a

Julie wrote: Jeff Schwab wrote:
Alex Vinokur wrote:
Why is not defined operator+ for vector? What would it mean?
This is a weak argument.
It's not an argument. It's a question.
There are plenty of methods/operators that are far from intuitive.
And more would help?
Take vector::empty(), for example.
Without prior (stl) knowledge, there is no way to know what this means: does it test for an empty condition or empty the contents of the vector?
You have a good point; a name like "is_empty" might have been better.  
P: n/a

Julie wrote: Jeff Schwab wrote: Alex Vinokur wrote: Why is not defined operator+ for vector? What would it mean?
Preamble: my previous response wasn't meant to be attacking or argumentative.
I don't disagree that specifically _operator_+_ is ambiguous and not warranted
for various reasons pointed out by other respondents.
This is a weak argument. There are plenty of methods/operators that are far from intuitive.
Take vector::empty(), for example.
Without prior (stl) knowledge, there is no way to know what this means: does it test for an empty condition or empty the contents of the vector?
For instance, vector<T> v1, v2, v3; T a;
v1=v2+a;
Does this make v1 the concatenation of v2 and a, or the result of adding a to each element of v2?
v1=v2+v3;
Does this add each element of v2 to the corresponding element from v3, or make v1 the concatenation of v2 and v3?
 
P: n/a

Jeff Schwab wrote: Julie wrote: Jeff Schwab wrote:
Alex Vinokur wrote:
Why is not defined operator+ for vector?
What would it mean?
This is a weak argument.
It's not an argument. It's a question.
Yep, you are absolutely correct. I wasn't thinking clearly at all when I
originally responded  you can safely ignore it. There are plenty of methods/operators that are far from intuitive. And more would help?
ibid. Take vector::empty(), for example.
Without prior (stl) knowledge, there is no way to know what this means: does it test for an empty condition or empty the contents of the vector?
You have a good point; a name like "is_empty" might have been better.  
P: n/a
 Take vector::empty(), for example.
Without prior (stl) knowledge, there is no way to know what this means: does it test for an empty condition or empty the contents of the vector?
Look at the full declaration
bool empty() const;
For sure no modifications, returns bool, what's not obvious about it??
JLR   This discussion thread is closed Replies have been disabled for this discussion.   Question stats  viewed: 2509
 replies: 10
 date asked: Jul 22 '05
