Newer
Older
/* Copyright (C) 2024 FIAS Frankfurt Institute for Advanced Studies, Frankfurt / Main
SPDX-License-Identifier: GPL-3.0-only
Authors: Felix Weiglhofer [committer] */
#pragma once
Dominik Smith
committed
#include <tuple>
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <type_traits>
/**
* @file AlgoTraits.h
* @brief Type traits for online algorithms
*/
namespace cbm::algo::algo_traits
{
namespace detail
{
template<typename...>
struct ResultOf {
};
template<typename R, typename Algo, typename... Args>
struct ResultOf<R (Algo::*)(Args...) const> {
using type = R;
};
template<typename R, typename Algo, typename... Args>
struct ResultOf<R (Algo::*)(Args...)> {
using type = R;
};
template<typename Algo>
struct ResultOf<Algo> : ResultOf<decltype(&Algo::operator())> {
};
} // namespace detail
/**
* @brief Type alias for the return type produced by an algorithm when invoked via callable-operator
*/
template<typename Algo>
using ResultOf_t = typename detail::ResultOf<Algo>::type;
Dominik Smith
committed
// Currently assume algorithms return std::tuple<R, M, A>
// where R is the output, M is the monitoring data and A is auxiliary data
/**
* @brief Type alias for the output type produced by an algorithm
*/
template<typename Algo>
Dominik Smith
committed
using Output_t = typename std::tuple_element<0, ResultOf_t<Algo>>::type;
/**
* @brief Type alias for the monitoring type produced by an algorithm
*/
template<typename Algo>
Dominik Smith
committed
using Monitor_t = typename std::tuple_element<1, ResultOf_t<Algo>>::type;
/**
* @brief Type alias for the auxiliary data type produced by an algorithm
*/
template<typename Algo>
using Aux_t = typename std::tuple_element<2, ResultOf_t<Algo>>::type;
} // namespace cbm::algo::algo_traits