ssmkit  master-68aed98
traits.hpp
Go to the documentation of this file.
1 
7 #ifndef SSMPACK_PROCESS_TRAITS_HPP
8 #define SSMPACK_PROCESS_TRAITS_HPP
9 
11 //exclude all from doxygen documantation
12 
15 
16 #include <type_traits>
17 
18 namespace ssmkit {
19 namespace process {
20 
21 template <typename T>
22 struct IsProcess : std::false_type {};
23 
24 template <typename A, typename B, typename C>
25 struct IsProcess<Markov<A, B, C>> : std::true_type {};
26 
27 template <typename A, typename B>
28 struct IsProcess<Memoryless<A, B>> : std::true_type {};
29 //==========================================
30 template <typename... Args>
31 struct AreProcesses;
32 
33 template <typename T, typename... Args>
34 struct AreProcesses<T, Args...> {
35  static constexpr bool value =
36  AreProcesses<Args...>::value && IsProcess<T>::value;
37 };
38 
39 template <>
40 struct AreProcesses<> {
41  static constexpr bool value = true;
42 };
43 //=====================================================
44 template <typename T>
45 struct ModelTraits {};
46 template <typename R, typename C, typename... Args>
47 struct ModelTraits<R (C::*)(Args...) const> {
48  // ok this is for constatnt, what about other cv and reference combinations ?
49  static constexpr size_t arity = sizeof...(Args);
50 };
51 
52 //==========================================
53 template <typename T>
54 struct ProcessTraits {
55  static constexpr bool valid = false;
56  using TPDF = void;
57  using TParamMap = void;
58  using TRandomVAR = void;
59  using type = T;
60 };
61 
62 template <typename T, typename U, typename V>
63 struct ProcessTraits<Markov<T, U, V>> {
64  static constexpr bool valid = true;
65  using TPDF = T;
66  using TParamMap = U;
67  using TRandomVAR = decltype(std::declval<TPDF>().random());
68  using type = Markov<T, U, V>;
69  using TArity = std::integral_constant<
70  size_t, ModelTraits<decltype(&TParamMap::operator())>::arity - 1>;
71 };
72 
73 template <typename T, typename U>
74 struct ProcessTraits<Memoryless<T, U>> {
75  static constexpr bool valid = true;
76  using TPDF = T;
77  using TParamMap = U;
78  using TRandomVAR = decltype(std::declval<TPDF>().random());
79  using type = Memoryless<T, U>;
80  using TArity = std::integral_constant<
81  size_t, ModelTraits<decltype(&TParamMap::operator())>::arity>;
82 };
83 }
84 }
86 #endif
87