Having an issue calling 'std::function<bool(const T*, const T*)> comp'
https://godbolt.org/z/7dTj5cKKn
#include <string>
#include <vector>
#include <functional>
class Type {
public:
Type(std::string name) : name(name) {}
std::string name;
};
class Types {
public:
Types(std::initializer_list<const Type*> types) : types(types) {}
Types(std::vector<const Type*> types) : types(types) {}
std::vector<const Type*> types;
};
typedef std::pair<const Type*, const Type*> Pair;
class TypeChecker {
public:
std::unordered_map<Pair, bool> subTypeMemorization;
bool isSubtype(const Type* lhs, const Type* rhs);
bool isSubtype(const Types* lhs, const Types* rhs);
bool isSubtype2(const Types* lhs, const Types* rhs);
};
template <class T>
std::vector<std::pair<const T, const T>> zip(std::vector< const T>* lhs, std::vector<const T>* rhs) {
assert(lhs->size() == rhs->size());
std::vector<std::pair<const T, const T>> result;
for (auto l = lhs->begin(), r = rhs->begin(); l != lhs->end(); ++l, ++r)
result.push_back(std::make_pair(*l, *r));
return result;
}
template <class T>
bool compare(const std::vector<const T*> lhs, const std::vector<const T*> rhs, std::function<bool(const T*, const T*)> comp) {
assert(lhs.size() == rhs.size());
for (auto l = lhs.begin(), r = rhs.begin(); l != lhs.end(); ++l, ++r)
if (comp(*l, *r))
return false;
return true;
}
template <class T>
bool compare(const std::vector<const T*> lhs, const std::vector<const T*> rhs, std::function<bool(TypeChecker*, const T*, const T*)> comp) {
assert(lhs.size() == rhs.size());
for (auto l = lhs.begin(), r = rhs.begin(); l != lhs.end(); ++l, ++r)
if (comp(*l, *r))
return false;
return true;
}
bool TypeChecker::isSubtype(const Types* lhs, const Types* rhs) {
return compare(lhs->types, rhs->types, [this](const Type* l, const Type* r) {
return this->isSubtype(l, r);
});
}
bool TypeChecker::isSubtype2(const Types* lhs, const Types* rhs) {
for (auto l = lhs->types.begin(), r = rhs->types.begin(); l != lhs->types.end(); ++l, ++r)
if (this->isSubtype(*l, *r))
return false;
return true;
}