diff --git a/include/podio/detail/Association.h b/include/podio/detail/Association.h index 0feaa7ee2..17100ee66 100644 --- a/include/podio/detail/Association.h +++ b/include/podio/detail/Association.h @@ -33,6 +33,23 @@ class AssociationT { friend AssociationCollectionIteratorT; friend AssociationT; + /// Helper member variable to check whether FromU and ToU can be used for this + /// Association. We need this to make SFINAE trigger in some cases below + template + constexpr static bool sameTypes = std::is_same_v && std::is_same_v; + + /// Variable template to for determining whether T is either FromT or ToT. + /// Mainly defined for convenience + template + static constexpr bool isFromOrToT = detail::isInTuple>; + + /// Variable template to for determining whether T is either FromT or ToT or + /// any of their mutable versions. + template + static constexpr bool isMutableFromOrToT = + detail::isInTuple, detail::GetMutableHandleType>>; + public: using mutable_type = podio::MutableAssociation; using value_type = podio::Association; @@ -57,15 +74,13 @@ class AssociationT { } /// Implicit conversion of mutable to immutable associations - template && std::is_same_v>> + template >> operator AssociationT() const { return AssociationT(m_obj); } /// Create a mutable deep-copy with identical relations - template && std::is_same_v>> + template >> MutableAssociation clone(bool cloneRelations = true) const { auto tmp = new AssociationObjT(podio::ObjectID{}, m_obj->weight); if (cloneRelations) { @@ -138,7 +153,7 @@ class AssociationT { /// /// @tparam T the desired type /// @returns T the element of the Association - template && detail::isFromOrToT>> + template && isFromOrToT>> T get() const { if constexpr (std::is_same_v) { return getFrom(); @@ -174,9 +189,7 @@ class AssociationT { /// /// @tparam T type of value (**infered!**) /// @param value the element to set for this association. - template < - typename T, - typename = std::enable_if_t && detail::isMutableFromOrToT>> + template && isMutableFromOrToT>> void set(T value) { if constexpr (std::is_same_v) { setFrom(std::move(value)); @@ -215,14 +228,12 @@ class AssociationT { return !(*this == other); } - template && std::is_same_v>> + template >> bool operator==(const AssociationT& other) const { return m_obj == other.m_obj; } - template && std::is_same_v>> + template >> bool operator!=(const AssociationT& other) const { return !(*this == other); } @@ -241,7 +252,7 @@ class AssociationT { explicit AssociationT(podio::utils::MaybeSharedPtr obj) : m_obj(std::move(obj)) { } - template > + template >> AssociationT(AssociationObjT* obj) : m_obj(podio::utils::MaybeSharedPtr(obj)) { } diff --git a/include/podio/detail/AssociationFwd.h b/include/podio/detail/AssociationFwd.h index 2d6d4cfd5..c3b74930d 100644 --- a/include/podio/detail/AssociationFwd.h +++ b/include/podio/detail/AssociationFwd.h @@ -12,17 +12,6 @@ namespace podio { namespace detail { - /// Variable template to for determining whether T is either FromT or ToT. - /// Mainly defined for convenience - template - static constexpr bool isFromOrToT = detail::isInTuple>; - - /// Variable template to for determining whether T is either FromT or ToT or - /// any of their mutable versions. - template - static constexpr bool isMutableFromOrToT = - detail::isInTuple, GetMutableHandleType>>; - /// Get the collection type name for an AssociationCollection /// /// @tparam FromT the From type of the association