From 7bb0c5c04673b8d611ce9c5bf1c2439dad7226be Mon Sep 17 00:00:00 2001
From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz>
Date: Wed, 12 Apr 2017 20:59:44 +0200
Subject: [PATCH] optimize normalisation of states

---
 .../src/automaton/common/AutomatonNormalize.h  | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)

diff --git a/alib2data/src/automaton/common/AutomatonNormalize.h b/alib2data/src/automaton/common/AutomatonNormalize.h
index 7951d558f1..8bfcd22e39 100644
--- a/alib2data/src/automaton/common/AutomatonNormalize.h
+++ b/alib2data/src/automaton/common/AutomatonNormalize.h
@@ -24,6 +24,12 @@ namespace automaton {
  * This class contains methods to print XML representation of automata to the output stream.
  */
 class AutomatonNormalize {
+	template < class StateType >
+	static DefaultStateType normalizeStateInternal ( typename std::enable_if < std::is_constructible < DefaultStateType, StateType >::value, StateType && >::type symbol );
+
+	template < class StateType >
+	static DefaultStateType normalizeStateInternal ( typename std::enable_if < ! std::is_constructible < DefaultStateType, StateType >::value, StateType && >::type symbol );
+
 public:
 	template < class StateType >
 	static std::set < DefaultStateType > normalizeStates ( std::set < StateType > && states );
@@ -61,10 +67,20 @@ std::vector < DefaultStateType > AutomatonNormalize::normalizeStates ( std::vect
 }
 
 template < class StateType >
-DefaultStateType AutomatonNormalize::normalizeState ( StateType && state) {
+DefaultStateType AutomatonNormalize::normalizeStateInternal ( typename std::enable_if < std::is_constructible < DefaultStateType, StateType >::value, StateType && >::type state ) {
+	return DefaultStateType ( std::move ( state ) );
+}
+
+template < class StateType >
+DefaultStateType AutomatonNormalize::normalizeStateInternal ( typename std::enable_if < ! std::is_constructible < DefaultStateType, StateType >::value, StateType && >::type state ) {
 	return DefaultStateType ( alib::AnyObject < StateType > ( std::move ( state ) ) );
 }
 
+template < class StateType >
+DefaultStateType AutomatonNormalize::normalizeState ( StateType && state) {
+	return AutomatonNormalize::normalizeStateInternal < StateType > ( std::move ( state ) );
+}
+
 template < class EpsilonType, class SymbolType >
 std::variant < DefaultEpsilonType, DefaultSymbolType > AutomatonNormalize::normalizeSymbolEpsilon ( std::variant < EpsilonType, SymbolType > && symbol ) {
 	if ( symbol.template is < EpsilonType > ( ) )
-- 
GitLab