Skip to content
Snippets Groups Projects

[Add] Possibility to create a GenericOperator from any Operator

Merged Olivier BICHLER requested to merge genericop_from_op into dev
2 unresolved threads
4 files
+ 43
7
Compare changes
  • Side-by-side
  • Inline
Files
4
@@ -34,6 +34,12 @@ namespace py = pybind11;
namespace Aidge {
// Detection idiom to check if a type T has a less-than operator
template <typename T, typename = void>
struct has_less_than_operator : std::false_type {};
template <typename T>
struct has_less_than_operator<T, std::void_t<decltype(std::declval<T>() < std::declval<T>())>> : std::true_type {};
///\todo store also a fix-sized code that indicates the type
///\todo managing complex types or excluding non-trivial, non-aggregate types
@@ -344,6 +350,14 @@ public:
}
};
template<typename T>
static inline typename std::enable_if<!has_less_than_operator<T>::value, void>::type makeTypeConditionallyAvailable() {}
template<typename T>
static inline typename std::enable_if<has_less_than_operator<T>::value, void>::type makeTypeConditionallyAvailable() {
mAnyUtils.emplace(typeid(T), std::unique_ptr<AnyUtils<T>>(new AnyUtils<T>()));
}
// Stores typed utils functions for each attribute type ever used
static std::map<std::type_index, std::unique_ptr<AnyUtils_>> mAnyUtils;
};
@@ -407,6 +421,19 @@ namespace std {
return seed;
}
};
// Special case for std::array
template <typename T, std::size_t N>
struct hash<std::array<T, N>> {
std::size_t operator()(const std::array<T, N>& iterable) const {
std::size_t seed = 0;
for (const auto& v : iterable) {
// Recursively hash the value pointed by the iterator
Aidge::hash_combine(seed, std::hash<T>()(v));
}
return seed;
}
};
}
namespace future_std {
Loading