BPMN-OS
BPMN for optimization and simulation
Loading...
Searching...
No Matches
expired.h
Go to the documentation of this file.
1
#ifndef BPMNOS_Execution_expired_H
2
#define BPMNOS_Execution_expired_H
3
4
#include <tuple>
5
#include <memory>
6
7
namespace
BPMNOS::Execution
{
8
9
template
<
typename
T>
10
struct
is_weak_ptr
: std::false_type {};
11
12
template
<
typename
T>
13
struct
is_weak_ptr
<
std
::weak_ptr<T>> : std::true_type {};
14
15
/**
16
* @brief Determines whether any of the initial weak_ptr elements in a tuple is expired.
17
*/
18
template
<std::size_t I = 0,
typename
... U>
19
bool
expired
(
const
std::tuple<U...> &t) {
20
if
constexpr
(I <
sizeof
...(U)) {
21
if
constexpr
(
is_weak_ptr
<
typename
std::tuple_element<I, std::tuple<U...>>::type>::value) {
22
// element is a weak_ptr
23
auto
wp = std::get<I>(t);
24
if
( wp.expired() ) {
25
// weak_ptr is expired
26
return
true
;
27
}
28
// recursively iterate over the rest of the tuple
29
return
expired<I + 1>
(t);
30
}
else
{
31
// first non-weak_ptr element found and none of the previous weak_ptr elements is expired
32
return
false
;
33
}
34
}
35
// no element is expired
36
return
false
;
37
}
38
39
}
// namespace BPMNOS::Execution
40
#endif
// BPMNOS_Execution_expired_H
BPMNOS::Execution
Definition
Controller.h:9
BPMNOS::Execution::expired
bool expired(const std::tuple< U... > &t)
Determines whether any of the initial weak_ptr elements in a tuple is expired.
Definition
expired.h:19
std
STL namespace.
BPMNOS::Execution::is_weak_ptr
Definition
expired.h:10