Fix C++11 compilation error / Chris Dyer

This commit is contained in:
Kenneth Heafield 2014-01-27 22:25:43 -08:00
parent 14e02978fc
commit ffd62e994e
2 changed files with 19 additions and 4 deletions

View File

@ -40,6 +40,12 @@ template <class KeyIter, class ValueIter> class JointIter {
swap(first.value_, second.value_);
}
void DeepSwap(JointIter &other) {
using std::swap;
swap(*key_, *other.key_);
swap(*value_, *other.value_);
}
private:
friend class JointProxy<KeyIter, ValueIter>;
KeyIter key_;
@ -84,10 +90,7 @@ template <class KeyIter, class ValueIter> class JointProxy {
}
friend void swap(JointProxy<KeyIter, ValueIter> first, JointProxy<KeyIter, ValueIter> second) {
// Allow argument-dependent lookup.
using std::swap;
swap(*first.inner_.key_, *second.inner_.key_);
swap(*first.inner_.value_, *second.inner_.value_);
first.Inner().DeepSwap(second.Inner());
}
private:

View File

@ -47,4 +47,16 @@ BOOST_AUTO_TEST_CASE(char_int) {
BOOST_CHECK_EQUAL(327, values[3]);
}
BOOST_AUTO_TEST_CASE(swap_proxy) {
char keys[2] = {0, 1};
int values[2] = {2, 3};
detail::JointProxy<char *, int *> first(keys, values);
detail::JointProxy<char *, int *> second(keys + 1, values + 1);
swap(first, second);
BOOST_CHECK_EQUAL(1, keys[0]);
BOOST_CHECK_EQUAL(0, keys[1]);
BOOST_CHECK_EQUAL(3, values[0]);
BOOST_CHECK_EQUAL(2, values[1]);
}
}} // namespace anonymous util