From 612e45e783ee54104f8586b9a30de1104fdbf493 Mon Sep 17 00:00:00 2001 From: bubnikv Date: Tue, 5 Nov 2019 11:46:05 +0100 Subject: [PATCH] std::exchange not supported by C++11. --- src/libslic3r/ElephantFootCompensation.cpp | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/libslic3r/ElephantFootCompensation.cpp b/src/libslic3r/ElephantFootCompensation.cpp index 7cbd05d69..0f4eb0135 100644 --- a/src/libslic3r/ElephantFootCompensation.cpp +++ b/src/libslic3r/ElephantFootCompensation.cpp @@ -11,7 +11,6 @@ #include #include -#include // #define CONTOUR_DISTANCE_DEBUG_SVG @@ -284,6 +283,14 @@ static inline INDEX_TYPE next_idx_cyclic(INDEX_TYPE idx, const CONTAINER &contai return idx; } +template +static inline T exchange(T& obj, U&& new_value) +{ + T old_value = std::move(obj); + obj = std::forward(new_value); + return old_value; +} + static inline void smooth_compensation_banded(const Points &contour, float band, std::vector &compensation, float strength, size_t num_iterations) { assert(contour.size() == compensation.size()); @@ -301,7 +308,7 @@ static inline void smooth_compensation_banded(const Points &contour, float band, float l2 = (pthis - pprev).squaredNorm(); if (l2 < dist_min2) { float l = sqrt(l2); - int jprev = std::exchange(j, prev_idx_cyclic(j, contour)); + int jprev = exchange(j, prev_idx_cyclic(j, contour)); while (j != i) { const Vec2f pp = contour[j].cast(); const float lthis = (pp - pprev).norm(); @@ -316,7 +323,7 @@ static inline void smooth_compensation_banded(const Points &contour, float band, prev = use_min ? std::min(prev, compensation[j]) : compensation[j]; pprev = pp; l = lnext; - jprev = std::exchange(j, prev_idx_cyclic(j, contour)); + jprev = exchange(j, prev_idx_cyclic(j, contour)); } } @@ -326,7 +333,7 @@ static inline void smooth_compensation_banded(const Points &contour, float band, l2 = (pprev - pthis).squaredNorm(); if (l2 < dist_min2) { float l = sqrt(l2); - int jprev = std::exchange(j, next_idx_cyclic(j, contour)); + int jprev = exchange(j, next_idx_cyclic(j, contour)); while (j != i) { const Vec2f pp = contour[j].cast(); const float lthis = (pp - pprev).norm(); @@ -341,7 +348,7 @@ static inline void smooth_compensation_banded(const Points &contour, float band, next = use_min ? std::min(next, compensation[j]) : compensation[j]; pprev = pp; l = lnext; - jprev = std::exchange(j, next_idx_cyclic(j, contour)); + jprev = exchange(j, next_idx_cyclic(j, contour)); } }