Fix issues with std::range::views using clang and C++20
This commit is contained in:
@@ -70,9 +70,9 @@ template <typename T> void Tarjan<T>::strongConnect(const T &u) {
|
||||
}
|
||||
|
||||
template <typename T> auto Tarjan<T>::execute() {
|
||||
for (const auto &u : std::views::keys(adjList)) {
|
||||
if (V[u].index == -1)
|
||||
strongConnect(u);
|
||||
for (const auto &u : adjList) {
|
||||
if (V[u.first].index == -1)
|
||||
strongConnect(u.first);
|
||||
}
|
||||
return SCCs;
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
|
||||
#include <ostream>
|
||||
#include <ranges>
|
||||
#include <vector>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
|
||||
@@ -38,8 +39,14 @@ public:
|
||||
std::unordered_map<T, std::unordered_set<T>> adjList;
|
||||
};
|
||||
|
||||
template <typename T> auto Graph<T>::vertices() const {
|
||||
return std::views::keys(adjList);
|
||||
template <typename T>
|
||||
auto Graph<T>::vertices() const {
|
||||
std::vector<T> keys;
|
||||
keys.reserve(adjList.size());
|
||||
for (const auto& pair : adjList) {
|
||||
keys.push_back(pair.first);
|
||||
}
|
||||
return keys;
|
||||
}
|
||||
|
||||
template <typename T> std::uint16_t Graph<T>::V() {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "algorithm/tarjan.h"
|
||||
#include "algorithm/breadth_first_search.h"
|
||||
|
||||
#include <memory>
|
||||
#include <random>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
@@ -51,7 +52,7 @@ TEST_SUITE("Algorithm") {
|
||||
};
|
||||
|
||||
for (auto i = 0; i < SCCs.size(); i++) {
|
||||
auto kv = std::views::keys(SCCs[i].adjList);
|
||||
auto kv = SCCs[i].vertices();
|
||||
CHECK_EQ(std::is_permutation(kv.begin(), kv.end(),
|
||||
expected[i].begin()), true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user