C++ STL - equivalent of operator function object templates with assignment? -


are there assignment operator objects in c++? std::plus, +=? (likewise minus, multiplies, divides, etc.)

edit - motivation:

i thought preferable avoid copy using function objects (std::plus(), etc.) in following code.

template<typename op> static vector<int>& memberwiseassignop(vector<int>& lhs, vector<int> rhs, op op) {     size_t const len = rhs.size();      if (len > lhs.size())     {         lhs.resize(len);     }      transform(lhs.begin(), lhs.end(), rhs.begin(), lhs.begin(), op);      return lhs; }   vector<int>& operator+=(vector<int>& lhs, vector<int> rhs) {     return memberwiseassignop(lhs, rhs, plus<int>()); }  vector<int>& operator-=(vector<int>& lhs, vector<int> rhs) {     return memberwiseassignop(lhs, rhs, minus<int>()); } 

more "no, it's not there", there's simple fact overloads of assignment operators need done member functions, can't done. guess, since we're dealing aren't operators though, done extent function written receive non-const reference object, , modify object referred.

i'm not @ sure you'd gain whole lot though. types made difference types substantially cheaper modify existing object overwrite old object new value.

at 1 time (before c++11), may have been fair number of types. since introduction of rvalue references can same effect (but more cleanly) moving old object new object, , modifying see fit along way.

in theory, there still few places wouldn't work out quite nicely. obvious example object (directly) contains lot of data, moving still works out copying.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -