Skip to content

Commit

Permalink
🎨 Test trait setup
Browse files Browse the repository at this point in the history
  • Loading branch information
ystade committed Mar 5, 2025
1 parent 6552eb1 commit 7c681ce
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions include/mqt-core/na/operations/Op.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,28 @@

#include <ostream>
#include <string>
#include <type_traits>

namespace na {
class Op {
template <typename ConcreteType, template <typename T> class... Traits>
class Op : public Traits<ConcreteType>... {
public:
Op() = default;
virtual ~Op() = default;
[[nodiscard]] virtual auto toString() const -> std::string = 0;
friend auto operator<<(std::ostream& os, const Op& obj) -> std::ostream& {
return os << obj.toString(); // Using toString() method
}
template <class T> [[nodiscard]] auto is() const -> bool {
return dynamic_cast<const T*>(this) != nullptr;
/// Checks whether the object has the template parameter as a trait.
template <template <typename T> class Trait>
[[nodiscard]] auto hasTrait() const -> bool {
return std::disjunction_v<
std::is_same<Trait<ConcreteType>, Traits<ConcreteType>>...>;
}
/// Checks whether the template parameter is the same type as the concrete
/// type of the object.
template <typename T> [[nodiscard]] auto is() const -> bool {
return std::is_same_v<T, ConcreteType>;
}
template <class T> [[nodiscard]] auto as() -> T& {
return dynamic_cast<T&>(*this);
Expand Down

0 comments on commit 7c681ce

Please sign in to comment.