From 2204cab4c87bf77fac56499bbfae90713de1e575 Mon Sep 17 00:00:00 2001 From: Francisco Paisana Date: Tue, 5 May 2020 18:32:01 +0100 Subject: [PATCH] old gcc version cannot support the detected pattern. Removing it --- lib/include/srslte/common/fsm.h | 41 +++++++++++++++++--------- lib/include/srslte/common/type_utils.h | 31 ------------------- lib/test/common/fsm_test.cc | 5 ++-- 3 files changed, 30 insertions(+), 47 deletions(-) diff --git a/lib/include/srslte/common/fsm.h b/lib/include/srslte/common/fsm.h index ac3a1befc..1fc1da192 100644 --- a/lib/include/srslte/common/fsm.h +++ b/lib/include/srslte/common/fsm.h @@ -97,10 +97,27 @@ using fsm_state_list_type = decltype(std::declval(). template using fsm_transitions = typename FSM::derived_view::transitions; -template -using enter_op_t = decltype(std::declval().enter(nullptr)); -template -using exit_op_t = decltype(std::declval().exit(nullptr)); +//! Detection of enter/exit methods of a state. +template +auto call_enter(FSM* f, State* s) -> decltype(s->enter(f), std::true_type{}) +{ + s->enter(f); + return std::true_type{}; +} +auto call_enter(...) -> std::false_type +{ + return {}; +} +template +auto call_exit(FSM* f, State* s) -> decltype(s->exit(f), std::true_type{}) +{ + s->exit(f); + return std::true_type{}; +} +auto call_exit(...) -> std::false_type +{ + return {}; +} //! Find State in FSM recursively (e.g. find State in FSM,FSM::parentFSM,FSM::parentFSM::parentFSM,...) template @@ -128,8 +145,8 @@ struct state_traits { static_assert(FSM::template can_hold_state(), "FSM type does not hold provided State\n"); using state_t = State; using is_subfsm = std::integral_constant()>; - using has_enter = type_utils::is_detected; - using has_exit = type_utils::is_detected; + using has_enter = decltype(fsm_details::call_enter((FSM*)nullptr, (State*)nullptr)); + using has_exit = decltype(fsm_details::call_exit((FSM*)nullptr, (State*)nullptr)); //! enter new state. enter is called recursively for subFSMs static void enter_state(FSM* f, State* s) { enter_(f, s, is_subfsm{}); } @@ -137,7 +154,7 @@ struct state_traits { template static enable_if_fsm_state transit_state(FSM* f) { - exit_if_exists_(f, &f->states.template get_unchecked(), has_exit{}); + call_exit(f, &f->states.template get_unchecked()); f->states.template transit(); state_traits::enter_state(f, &f->states.template get_unchecked()); } @@ -145,7 +162,7 @@ struct state_traits { static disable_if_fsm_state transit_state(FSM* f) { using parent_state_traits = state_traits; - exit_if_exists_(f, &f->states.template get_unchecked(), has_exit{}); + call_exit(f, &f->states.template get_unchecked()); parent_state_traits::template transit_state(get_derived(f->parent_fsm())); } @@ -157,17 +174,13 @@ private: // set default FSM type get_derived(s)->states.template transit(); // call FSM enter function - enter_if_exists_(f, s, has_enter{}); + call_enter(f, s); // call initial substate enter state_traits::enter_state( get_derived(s), &get_derived(s)->states.template get_unchecked()); } //! In case of State is basic state - static void enter_(FSM* f, State* s, std::false_type) { enter_if_exists_(f, s, has_enter{}); } - static void enter_if_exists_(FSM* f, State* s, std::true_type) { s->enter(f); } - static void enter_if_exists_(FSM* f, State* s, std::false_type) {} - static void exit_if_exists_(FSM* f, State* s, std::true_type) { s->exit(f); } - static void exit_if_exists_(FSM* f, State* s, std::false_type) {} + static void enter_(FSM* f, State* s, std::false_type) { call_enter(f, s); } }; //! Trigger Event reaction for the first Row for which the Guard passes diff --git a/lib/include/srslte/common/type_utils.h b/lib/include/srslte/common/type_utils.h index 9f46e73c5..fd31faa4f 100644 --- a/lib/include/srslte/common/type_utils.h +++ b/lib/include/srslte/common/type_utils.h @@ -209,37 +209,6 @@ struct filter { using type = type_list<>; }; -/************************** - * Detect Pattern - *************************/ - -template -using voider = void; - -template class Op, class... Args> -struct detector { - using value_t = std::false_type; - using type = Default; -}; - -template class Op, class... Args> -struct detector >, Op, Args...> { - using value_t = std::true_type; - using type = Op; -}; - -template