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