assignment operator overloading in c++

There are no problems with the second version of the assignment operator. In fact, that is the standard way for an assignment operator. Edit: Note that I am referring to the return type of the assignment operator, not to the implementation itself. As has been pointed out in comments, the implementation itself is another issue. … Read more

Solution for overloaded operator constraint in .NET generics

There is no immediate answer; operators are static, and cannot be expressed in constraints – and the existing primatives don’t implement any specific interface (contrast to IComparable[<T>] which can be used to emulate greater-than / less-than). However; if you just want it to work, then in .NET 3.5 there are some options… I have put … Read more

Are free operator->* overloads evil?

The best example I am aware of is Boost.Phoenix, which overloads this operator to implement lazy member access. For those unfamiliar with Phoenix, it is a supremely nifty library for building actors (or function objects) that look like normal expressions: ( arg1 % 2 == 1 ) // this expression evaluates to an actor (3); … Read more

Why does Python have an __ne__ operator method instead of just __eq__?

SQLAlchemy is a great example. For the uninitiated, SQLAlchemy is a ORM and uses Python expression to generate SQL statements. In a expression such as meta.Session.query(model.Theme).filter(model.Theme.id == model.Vote.post_id) the model.Theme.id == model.VoteWarn.post_id does not return a boolean, but a object that eventually produces a SQL query like WHERE theme.id = vote.post_id. The inverse would produce … Read more

Is negative index for operator[] well defined?

This is well defined, both syntactically and semantically. [expr.sub]/1 (N3337): The expression E1[E2] is identical (by definition) to *((E1)+(E2)). So your expression is the same as *(q-1) = 41;, so is syntactically valid. [expr.add]/5 (N3337) When an expression that has integral type is added to or subtracted from a pointer, the result has the type … Read more