Skip to content

Commit 7f86010

Browse files
authored
Merge pull request #45770 from Dr15Jones/ptrConcepts
Use C++ concepts for edm::Ptr
2 parents a1d42f0 + faf33ed commit 7f86010

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

DataFormats/Common/interface/Ptr.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ namespace edm {
109109
Ptr() : core_(), key_(key_traits<key_type>::value) {}
110110

111111
template <typename U>
112-
Ptr(Ptr<U> const& iOther, std::enable_if_t<std::is_base_of<T, U>::value>* = nullptr)
112+
requires std::is_base_of_v<T, U>
113+
Ptr(Ptr<U> const& iOther)
113114
: core_(iOther.id(),
114115
(iOther.hasProductCache() ? static_cast<T const*>(iOther.get()) : static_cast<T const*>(nullptr)),
115116
iOther.productGetter(),
@@ -123,7 +124,8 @@ namespace edm {
123124
}
124125

125126
template <typename U>
126-
explicit Ptr(Ptr<U> const& iOther, std::enable_if_t<std::is_base_of<U, T>::value>* = nullptr)
127+
requires std::is_base_of_v<U, T>
128+
explicit Ptr(Ptr<U> const& iOther)
127129
: core_(iOther.id(), dynamic_cast<T const*>(iOther.get()), nullptr, iOther.isTransient()), key_(iOther.key()) {}
128130

129131
/// Destructor

DataFormats/Common/test/ptr_t.cppunit.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ void testPtr::constructTest() {
207207
CPPUNIT_ASSERT(dummy2Ptr.key() == copyPtr.key());
208208
CPPUNIT_ASSERT(dummy2Ptr.get() == static_cast<const Dummy*>(dummy2Ptr.get()));
209209

210+
Ptr<Dummy> copyCtrPtr(copyPtr);
211+
CPPUNIT_ASSERT(copyPtr.key() == copyCtrPtr.key());
212+
210213
Ptr<Dummy> movePtr(std::move(copyPtr));
211214
CPPUNIT_ASSERT(dummy2Ptr.key() == movePtr.key());
212215
}

0 commit comments

Comments
 (0)