diff --git a/src/lol/algorithm/sort.h b/src/lol/algorithm/sort.h index 9af79092..ee8a10a1 100644 --- a/src/lol/algorithm/sort.h +++ b/src/lol/algorithm/sort.h @@ -30,7 +30,7 @@ void array_base::shuffle() while (n > 0) { ni = lol::rand(n--) | 0; - std::swap(m_data[ni], m_data[n]); + this->swap(ni, n); } } @@ -59,7 +59,7 @@ void array_base::sort(SortAlgorithm algorithm) d = 1; if (m_data[i + 1] < m_data[i]) { - std::swap(m_data[i], m_data[i + 1]); + this->swap(i, i + 1); d = -1; } } @@ -103,7 +103,7 @@ static void quick_swap_sort(array_base &a, { if (!(a[i0] < median) && a[i1] < median) { - std::swap(a[i0], a[i1]); + a.swap(i0, i1); i0++; i1--; b_swap = true; diff --git a/src/lol/base/array.h b/src/lol/base/array.h index b04c3915..812497af 100644 --- a/src/lol/base/array.h +++ b/src/lol/base/array.h @@ -286,6 +286,15 @@ public: return tmp; } + inline void swap(ptrdiff_t i, ptrdiff_t j) + { + ASSERT(i >= 0 && i < m_count && j >= 0 && j < m_count, + "cannot swap elements %lld and %lld in array of size %lld", + (long long int)i, (long long int)j, (long long int)m_count); + + std::swap(m_data[i], m_data[j]); + } + void remove(ptrdiff_t pos, ptrdiff_t todelete = 1) { ASSERT(todelete >= 0); diff --git a/src/lol/math/noise/simplex.h b/src/lol/math/noise/simplex.h index b48c426e..79110c49 100644 --- a/src/lol/math/noise/simplex.h +++ b/src/lol/math/noise/simplex.h @@ -1,13 +1,14 @@ // -// Lol Engine +// Lol Engine // -// Copyright: (c) 2010-2014 Sam Hocevar -// (c) 2013-2014 Benjamin "Touky" Huet -// (c) 2013-2014 Guillaume Bittoun -// This program is free software; you can redistribute it and/or -// modify it under the terms of the Do What The Fuck You Want To -// Public License, Version 2, as published by Sam Hocevar. See -// http://www.wtfpl.net/ for more details. +// Copyright: © 2010—2014 Sam Hocevar +// © 2013—2014 Benjamin "Touky" Huet +// © 2013—2014 Guillaume Bittoun +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the Do What The Fuck You Want To +// Public License, Version 2, as published by Sam Hocevar. See +// http://www.wtfpl.net/ for more details. // #pragma once @@ -94,7 +95,7 @@ protected: for (int i = 0; i < N; ++i) for (int j = i + 1; j < N; ++j) if (pos[traversal_order[i]] < pos[traversal_order[j]]) - std::swap(traversal_order[i], traversal_order[j]); + traversal_order.swap(i, j); /* Get the position in world coordinates, too */ diff --git a/src/t/base/array.cpp b/src/t/base/array.cpp index 8506e683..e95d0877 100644 --- a/src/t/base/array.cpp +++ b/src/t/base/array.cpp @@ -1,11 +1,12 @@ // -// Lol Engine +// Lol Engine — unit tests // -// Copyright: (c) 2010-2014 Sam Hocevar -// This program is free software; you can redistribute it and/or -// modify it under the terms of the Do What The Fuck You Want To -// Public License, Version 2, as published by Sam Hocevar. See -// http://www.wtfpl.net/ for more details. +// Copyright: © 2010—2014 Sam Hocevar +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the Do What The Fuck You Want To +// Public License, Version 2, as published by Sam Hocevar. See +// http://www.wtfpl.net/ for more details. // #include @@ -159,7 +160,7 @@ lolunit_declare_fixture(ArrayTest) a.push(10, 20); a.push(30, 40); - std::swap(a[0], a[1]); + a.swap(0, 1); lolunit_assert_equal(30, a[0].m1); lolunit_assert_equal(40, a[0].m2);