Why would the assignment operator ever do something different than its matching constructor?

Posted by Neil G on Stack Overflow See other posts from Stack Overflow or by Neil G
Published on 2010-05-14T01:07:43Z Indexed on 2010/05/14 1:14 UTC
Read the original article Hit count: 265

I was reading some boost code, and came across this:

inline sparse_vector &assign_temporary(sparse_vector &v) {
    swap(v);
    return *this;
}
template<class AE>
    inline sparse_vector &operator=(const sparse_vector<AE> &ae) {
        self_type temporary(ae);
        return assign_temporary(temporary);
    }

It seems to be mapping all of the constructors to assignment operators. Great. But why did C++ ever opt to make them do different things? All I can think of is scoped_ptr?

© Stack Overflow or respective owner

Related posts about c++

Related posts about assignment-operator