aboutsummaryrefslogtreecommitdiffstats
path: root/common/nextpnr.h
diff options
context:
space:
mode:
authorDavid Shah <dave@ds0.me>2020-12-30 20:37:07 +0000
committerGitHub <noreply@github.com>2020-12-30 20:37:07 +0000
commitc6cdf30501dcb2da01361229dd66a05dad73a132 (patch)
treeb91338acfa13c2b53fe48105eb6ffa7639533469 /common/nextpnr.h
parent818faa78aaac168742a1f2140de5f4c18c846348 (diff)
parent60276e34479e61307968c371c4af247bedf30c8f (diff)
downloadnextpnr-c6cdf30501dcb2da01361229dd66a05dad73a132.tar.gz
nextpnr-c6cdf30501dcb2da01361229dd66a05dad73a132.tar.bz2
nextpnr-c6cdf30501dcb2da01361229dd66a05dad73a132.zip
Merge pull request #548 from per-gron/c++17
C++17 compatibility: Don't use std::random_shuffle
Diffstat (limited to 'common/nextpnr.h')
-rw-r--r--common/nextpnr.h14
1 files changed, 10 insertions, 4 deletions
diff --git a/common/nextpnr.h b/common/nextpnr.h
index f9376fea..5fa946e1 100644
--- a/common/nextpnr.h
+++ b/common/nextpnr.h
@@ -631,15 +631,21 @@ struct DeterministicRNG
rng64();
}
- template <typename T> void shuffle(std::vector<T> &a)
+ template <typename Iter> void shuffle(const Iter& begin, const Iter& end)
{
- for (size_t i = 0; i != a.size(); i++) {
- size_t j = i + rng(a.size() - i);
+ size_t size = end - begin;
+ for (size_t i = 0; i != size; i++) {
+ size_t j = i + rng(size - i);
if (j > i)
- std::swap(a[i], a[j]);
+ std::swap(*(begin + i), *(begin + j));
}
}
+ template <typename T> void shuffle(std::vector<T> &a)
+ {
+ shuffle(a.begin(), a.end());
+ }
+
template <typename T> void sorted_shuffle(std::vector<T> &a)
{
std::sort(a.begin(), a.end());