From 211cd7a36342047511ae2aa501383abf263643c1 Mon Sep 17 00:00:00 2001 From: Xpol Wan Date: Tue, 14 Jun 2016 17:20:49 +0800 Subject: [PATCH] make binary arithmetic operators for column_t non-member. --- include/xlnt/cell/index_types.hpp | 18 +++++++++--------- source/cell/index_types.cpp | 25 +++++-------------------- 2 files changed, 14 insertions(+), 29 deletions(-) diff --git a/include/xlnt/cell/index_types.hpp b/include/xlnt/cell/index_types.hpp index 9af99b87..a2378480 100644 --- a/include/xlnt/cell/index_types.hpp +++ b/include/xlnt/cell/index_types.hpp @@ -231,27 +231,27 @@ public: /// /// Return the result of adding rhs to this column. /// - column_t operator+(const column_t &rhs); + friend column_t operator+(column_t lhs, const column_t& rhs); /// - /// Return the result of adding rhs to this column. + /// Return the result of subtracing lhs by rhs column. /// - column_t operator-(const column_t &rhs); + friend column_t operator-(column_t lhs, const column_t& rhs); /// - /// Return the result of adding rhs to this column. + /// Return the result of multiply lhs by rhs column. /// - column_t operator*(const column_t &rhs); + friend column_t operator*(column_t lhs, const column_t& rhs); /// - /// Return the result of adding rhs to this column. + /// Return the result of divide lhs by rhs column. /// - column_t operator/(const column_t &rhs); + friend column_t operator/(column_t lhs, const column_t& rhs); /// - /// Return the result of adding rhs to this column. + /// Return the result of mod lhs by rhs column. /// - column_t operator%(const column_t &rhs); + friend column_t operator%(column_t lhs, const column_t& rhs); /// /// Add rhs to this column and return a reference to this column. diff --git a/source/cell/index_types.cpp b/source/cell/index_types.cpp index c97557b6..4b789a51 100644 --- a/source/cell/index_types.cpp +++ b/source/cell/index_types.cpp @@ -252,30 +252,15 @@ column_t column_t::operator++(int) { column_t copy(index); ++(*this); return cop /// column_t column_t::operator--(int) { column_t copy(index); --(*this); return copy; } -/// -/// Return the result of adding rhs to this column. -/// -column_t column_t::operator+(const column_t &rhs) { column_t copy(*this); copy.index += rhs.index; return copy; } +column_t operator+(column_t lhs, const column_t& rhs) { lhs += rhs; return lhs; } -/// -/// Return the result of adding rhs to this column. -/// -column_t column_t::operator-(const column_t &rhs) { column_t copy(*this); copy.index -= rhs.index; return copy; } +column_t operator-(column_t lhs, const column_t& rhs) { lhs -= rhs; return lhs; } -/// -/// Return the result of adding rhs to this column. -/// -column_t column_t::operator*(const column_t &rhs) { column_t copy(*this); copy.index *= rhs.index; return copy; } +column_t operator*(column_t lhs, const column_t& rhs) { lhs *= rhs; return lhs; } -/// -/// Return the result of adding rhs to this column. -/// -column_t column_t::operator/(const column_t &rhs) { column_t copy(*this); copy.index /= rhs.index; return copy; } +column_t operator/(column_t lhs, const column_t& rhs) { lhs /= rhs; return lhs; } -/// -/// Return the result of adding rhs to this column. -/// -column_t column_t::operator%(const column_t &rhs) { column_t copy(*this); copy.index %= rhs.index; return copy; } +column_t operator%(column_t lhs, const column_t& rhs) { lhs %= rhs; return lhs; } /// /// Add rhs to this column and return a reference to this column.