Skip to content

Commit b574ea1

Browse files
committed
DPL: use concepts rather than SFINAE
Notice that we do not impose the arguments, so that we still get a compilation error if they are wrong.
1 parent f68a63e commit b574ea1

File tree

1 file changed

+6
-61
lines changed
  • Framework/Core/include/Framework

1 file changed

+6
-61
lines changed

Framework/Core/include/Framework/Task.h

Lines changed: 6 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -14,66 +14,11 @@
1414
#include "Framework/AlgorithmSpec.h"
1515
#include "Framework/CallbackService.h"
1616
#include "Framework/EndOfStreamContext.h"
17-
#include <utility>
1817
#include <memory>
1918

2019
namespace o2::framework
2120
{
2221

23-
/// Check if the class task has EndOfStream
24-
template <typename T>
25-
class has_endOfStream
26-
{
27-
typedef char one;
28-
struct two {
29-
char x[2];
30-
};
31-
32-
template <typename C>
33-
static one test(decltype(&C::endOfStream));
34-
template <typename C>
35-
static two test(...);
36-
37-
public:
38-
enum { value = sizeof(test<T>(nullptr)) == sizeof(char) };
39-
};
40-
41-
/// Check if the class task has EndOfStream
42-
template <typename T>
43-
class has_finaliseCCDB
44-
{
45-
typedef char one;
46-
struct two {
47-
char x[2];
48-
};
49-
50-
template <typename C>
51-
static one test(decltype(&C::finaliseCCDB));
52-
template <typename C>
53-
static two test(...);
54-
55-
public:
56-
enum { value = sizeof(test<T>(nullptr)) == sizeof(char) };
57-
};
58-
59-
/// Check if the class task has Stop
60-
template <typename T>
61-
class has_stop
62-
{
63-
typedef char one;
64-
struct two {
65-
char x[2];
66-
};
67-
68-
template <typename C>
69-
static one test(decltype(&C::stop));
70-
template <typename C>
71-
static two test(...);
72-
73-
public:
74-
enum { value = sizeof(test<T>(nullptr)) == sizeof(char) };
75-
};
76-
7722
/// A more familiar task API for the DPL.
7823
/// This allows you to define your own tasks as subclasses
7924
/// of o2::framework::Task and to pass them in the specification
@@ -115,19 +60,19 @@ AlgorithmSpec adaptFromTask(Args&&... args)
11560
{
11661
return AlgorithmSpec::InitCallback{[=](InitContext& ic) {
11762
auto task = std::make_shared<T>(args...);
118-
if constexpr (has_endOfStream<T>::value) {
63+
if constexpr (requires { &T::endOfStream; }) {
11964
auto& callbacks = ic.services().get<CallbackService>();
12065
callbacks.set<CallbackService::Id::EndOfStream>([task](EndOfStreamContext& eosContext) {
12166
task->endOfStream(eosContext);
12267
});
12368
}
124-
if constexpr (has_finaliseCCDB<T>::value) {
69+
if constexpr (requires { &T::finaliseCCDB; }) {
12570
auto& callbacks = ic.services().get<CallbackService>();
12671
callbacks.set<CallbackService::Id::CCDBDeserialised>([task](ConcreteDataMatcher& matcher, void* obj) {
12772
task->finaliseCCDB(matcher, obj);
12873
});
12974
}
130-
if constexpr (has_stop<T>::value) {
75+
if constexpr (requires { &T::stop; }) {
13176
auto& callbacks = ic.services().get<CallbackService>();
13277
callbacks.set<CallbackService::Id::Stop>([task]() {
13378
task->stop();
@@ -144,19 +89,19 @@ template <typename T>
14489
AlgorithmSpec adoptTask(std::shared_ptr<T> task)
14590
{
14691
return AlgorithmSpec::InitCallback{[task](InitContext& ic) {
147-
if constexpr (has_endOfStream<T>::value) {
92+
if constexpr (requires { &T::endOfStream; }) {
14893
auto& callbacks = ic.services().get<CallbackService>();
14994
callbacks.set<CallbackService::Id::EndOfStream>([task](EndOfStreamContext& eosContext) {
15095
task->endOfStream(eosContext);
15196
});
15297
}
153-
if constexpr (has_finaliseCCDB<T>::value) {
98+
if constexpr (requires { &T::finaliseCCDB; }) {
15499
auto& callbacks = ic.services().get<CallbackService>();
155100
callbacks.set<CallbackService::Id::CCDBDeserialised>([task](ConcreteDataMatcher& matcher, void* obj) {
156101
task->finaliseCCDB(matcher, obj);
157102
});
158103
}
159-
if constexpr (has_stop<T>::value) {
104+
if constexpr (requires { &T::stop; }) {
160105
auto& callbacks = ic.services().get<CallbackService>();
161106
callbacks.set<CallbackService::Id::Stop>([task]() {
162107
task->stop();

0 commit comments

Comments
 (0)