Skip to content

Commit

Permalink
DPL: Drop generic code chose between unique and shared pointers
Browse files Browse the repository at this point in the history
Just use an if constexpr nowadays...
  • Loading branch information
ktf committed Sep 18, 2024
1 parent c8e9b40 commit 5189fa6
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 77 deletions.
1 change: 0 additions & 1 deletion Framework/Core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ add_executable(o2-test-framework-core
test/test_OptionsHelpers.cxx
test/test_OverrideLabels.cxx
test/test_O2DataModelHelpers.cxx
test/test_PtrHelpers.cxx
test/test_RootConfigParamHelpers.cxx
test/test_Services.cxx
test/test_StringHelpers.cxx
Expand Down
27 changes: 0 additions & 27 deletions Framework/Core/include/Framework/TypeTraits.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,32 +164,5 @@ struct has_root_setowner<
void>> : public std::true_type {
};

/// Helper class to deal with the case we are creating the first instance of a
/// (possibly) shared resource.
///
/// works for both:
///
/// std::shared_ptr<Base> storage = make_matching<decltype(storage), Concrete1>(args...);
///
/// or
///
/// std::unique_ptr<Base> storage = make_matching<decltype(storage), Concrete1>(args...);
///
/// Useful to deal with those who cannot make up their mind about ownership.
/// ;-)
template <typename HOLDER, typename T, typename... ARGS>
static std::enable_if_t<sizeof(std::declval<HOLDER>().unique()) != 0, HOLDER>
make_matching(ARGS&&... args)
{
return std::make_shared<T>(std::forward<ARGS>(args)...);
}

template <typename HOLDER, typename T, typename... ARGS>
static std::enable_if_t<sizeof(std::declval<HOLDER>().get_deleter()) != 0, HOLDER>
make_matching(ARGS&&... args)
{
return std::make_unique<T>(std::forward<ARGS>(args)...);
}

} // namespace o2::framework
#endif // FRAMEWORK_TYPETRAITS_H
5 changes: 1 addition & 4 deletions Framework/Core/src/runDataProcessing.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1098,10 +1098,7 @@ int doChild(int argc, char** argv, ServiceRegistry& serviceRegistry,
serviceRef.registerService(ServiceRegistryHelpers::handleForService<DeviceContext>(deviceContext.get()));
serviceRef.registerService(ServiceRegistryHelpers::handleForService<DriverConfig const>(&driverConfig));

// The decltype stuff is to be able to compile with both new and old
// FairMQ API (one which uses a shared_ptr, the other one a unique_ptr.
decltype(r.fDevice) device;
device = make_matching<decltype(device), DataProcessingDevice>(ref, serviceRegistry, processingPolicies);
auto device = std::make_unique<DataProcessingDevice>(ref, serviceRegistry, processingPolicies);

serviceRef.get<RawDeviceService>().setDevice(device.get());
r.fDevice = std::move(device);
Expand Down
45 changes: 0 additions & 45 deletions Framework/Core/test/test_PtrHelpers.cxx

This file was deleted.

0 comments on commit 5189fa6

Please sign in to comment.