From 7937be5d14228870ca1266ac1ce2229b179b6e5b Mon Sep 17 00:00:00 2001 From: KRM7 <70973547+KRM7@users.noreply.github.com> Date: Wed, 14 Aug 2024 19:41:43 +0200 Subject: [PATCH] use custom struct for CandidatePair instead of std::pair --- src/core/candidate.hpp | 6 +++++- src/core/ga_base.impl.hpp | 6 +++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/core/candidate.hpp b/src/core/candidate.hpp index dc63c08f..2ee3f458 100644 --- a/src/core/candidate.hpp +++ b/src/core/candidate.hpp @@ -135,7 +135,11 @@ namespace gapp /** A pair of candidates. */ template - using CandidatePair = std::pair, Candidate>; + struct CandidatePair + { + Candidate first; + Candidate second; + }; /** diff --git a/src/core/ga_base.impl.hpp b/src/core/ga_base.impl.hpp index 47d5e28b..5604a6f5 100644 --- a/src/core/ga_base.impl.hpp +++ b/src/core/ga_base.impl.hpp @@ -493,9 +493,9 @@ namespace gapp prepareSelections(); detail::parallel_for(detail::iota_iterator(0_sz), detail::iota_iterator(population_size_ / 2), [&](size_t i) { - Candidate& child1 = children[2 * i]; - Candidate& child2 = children[2 * i + 1]; - std::tie(child1, child2) = crossover(select(), select()); + CandidatePair child_pair = crossover(select(), select()); + children[2 * i] = std::move(child_pair.first); + children[2 * i + 1] = std::move(child_pair.second); }); if (population_size_ % 2) children.back() = crossover(select(), select()).first;