From 237a1a0dc4e402f93255cfc44a945fd1dd3349db Mon Sep 17 00:00:00 2001 From: JaMiT Date: Sun, 2 Mar 2014 13:50:24 -0600 Subject: [PATCH] Fix compilation on MSVC. MSVC was throwing error C2244 when trying to match some function definitions to their declarations. This commit moves those definitions to their declarations. The declarations are harder for a human to read now, but at least all supported compilers can understand it. --- src/utils/smart_list.hpp | 72 +++++++++++++++++----------------------- 1 file changed, 30 insertions(+), 42 deletions(-) diff --git a/src/utils/smart_list.hpp b/src/utils/smart_list.hpp index 5ca530506cd6..e42621aaed64 100644 --- a/src/utils/smart_list.hpp +++ b/src/utils/smart_list.hpp @@ -112,7 +112,20 @@ class smart_list ~iterator_base() { unref(ptr_); } // Assignment - iterator_base & operator=(const iterator_base & that); + iterator_base & operator=(const iterator_base & that) + // NOTE: This is defined here because MSVC was unable to match the + // definition to the declaration when they were separate. + { + // Update our pointer. + node_t * old_ptr = ptr_; + ptr_ = that.ptr_; + + // Update reference counts. + refer(); + unref(old_ptr); + + return *this; + } // Comparison: bool operator==(const iterator_base & that) const { return ptr_ == that.ptr_; } @@ -125,8 +138,22 @@ class smart_list // Increment/decrement: iterator_base & operator++() { advance(Reversed); return *this; } iterator_base & operator--() { advance(!Reversed); return *this; } - iterator_base operator++(int); - iterator_base operator--(int); + iterator_base operator++(int) + // NOTE: This is defined here because MSVC was unable to match the + // definition to the declaration when they were separate. + { + iterator_base retval(*this); + advance(Reversed); + return retval; + } + iterator_base operator--(int) + // NOTE: This is defined here because MSVC was unable to match the + // definition to the declaration when they were separate. + { + iterator_base retval(*this); + advance(!Reversed); + return retval; + } /// Test for being in a list, rather than past-the-end (or unassigned). bool derefable() const { return derefable(ptr_); } @@ -744,45 +771,6 @@ inline smart_list::node_t::~node_t() /* ** smart_list::iterator_base ** */ -/** Assignment */ -template -template -inline typename smart_list::template iterator_base & - smart_list::iterator_base::operator= - (const iterator_base & that) -{ - // Update our pointer. - node_t * old_ptr = ptr_; - ptr_ = that.ptr_; - - // Update reference counts. - refer(); - unref(old_ptr); - - return *this; -} - -/** Post-increment */ -template -template -inline typename smart_list::template iterator_base - smart_list::iterator_base::operator++(int) -{ - iterator_base retval(*this); - advance(Reversed); - return retval; -} -/** Post-decrement */ -template -template -inline typename smart_list::template iterator_base - smart_list::iterator_base::operator--(int) -{ - iterator_base retval(*this); - advance(!Reversed); - return retval; -} - /** * Advances our pointer to an unflagged node, possibly in the reverse direction. * This will advance at least one step, and will not stop on a flagged node.