From d35f8489b8b2110f350bc90e7a6f1b01ba4a81ce Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Fri, 7 Jul 2017 18:50:20 +0200 Subject: [PATCH] allow detection of normalizable datatype --- alib2data/src/automaton/FSM/NFA.h | 2 ++ alib2std/src/extensions/type_traits.hpp | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/alib2data/src/automaton/FSM/NFA.h b/alib2data/src/automaton/FSM/NFA.h index cbf2077c1c..71aa2a44d0 100644 --- a/alib2data/src/automaton/FSM/NFA.h +++ b/alib2data/src/automaton/FSM/NFA.h @@ -193,6 +193,8 @@ public: virtual alib::ObjectBase * inc ( ) &&; + typedef NFA < > normalized_type; + virtual AutomatonBase * normalize ( ) && { if ( typeid ( NFA < > ) == typeid ( NFA < SymbolType, StateType > ) ) return this; diff --git a/alib2std/src/extensions/type_traits.hpp b/alib2std/src/extensions/type_traits.hpp index 459bb5acfb..05e27fdb6b 100644 --- a/alib2std/src/extensions/type_traits.hpp +++ b/alib2std/src/extensions/type_traits.hpp @@ -23,6 +23,17 @@ namespace std { static const bool value = sizeof(Yes) == sizeof(has_clone::test((typename std::remove_reference<T>::type*)0)); }; + template<class T> + struct has_normalize { + typedef char (&Yes)[1]; + typedef char (&No)[2]; + + template<class U> + static Yes test(U * data, typename std::enable_if< std::is_pointer<decltype(data->normalize())>::value>::type * = 0); + static No test(...); + static const bool value = sizeof(Yes) == sizeof(has_normalize::test((typename std::remove_reference<T>::type*)0)); + }; + // ---------------------------------------------------------------------------------------------------- template <typename T> -- GitLab