diff --git a/alib2algo/src/automaton/generate/RandomTreeAutomatonFactory.h b/alib2algo/src/automaton/generate/RandomTreeAutomatonFactory.h index 2b2eb7e694c37daed42fb377ff8d51fe0989891b..5620dd7809e400f19cee6dc78c74536e67d7a14a 100644 --- a/alib2algo/src/automaton/generate/RandomTreeAutomatonFactory.h +++ b/alib2algo/src/automaton/generate/RandomTreeAutomatonFactory.h @@ -131,7 +131,6 @@ automaton::NFTA < SymbolType, unsigned > RandomTreeAutomatonFactory::LeslieConne ext::deque<bool> VStates; ext::deque<unsigned> Q; - size_t unvisited; automaton::NFTA < SymbolType, unsigned > automaton; @@ -149,16 +148,16 @@ automaton::NFTA < SymbolType, unsigned > RandomTreeAutomatonFactory::LeslieConne } else if( n == 1 ) { automaton.addTransition( nullaryAlphabet[ ext::random_devices::semirandom() % nullaryAlphabet.size( ) ], ext::vector < unsigned > { }, Q[ 0 ] ); - unvisited = 0; VStates[ 0 ] = true; } else { unsigned x = ext::random_devices::semirandom() % n; automaton.addTransition( nullaryAlphabet[ ext::random_devices::semirandom() % nullaryAlphabet.size( ) ], ext::vector < unsigned > { }, Q[ x ] ); - unvisited = n - 1; VStates[ x ] = true; } + size_t unvisited = n - 1; + while( unvisited != 0 ) { int c = ext::random_devices::semirandom() % alphabet.size( ); ext::vector < unsigned > from; diff --git a/alib2algo/src/regexp/glushkov/GlushkovFollow.h b/alib2algo/src/regexp/glushkov/GlushkovFollow.h index d75fc638506428e25536c7a94eab5d21c3fd705f..85af7649797588e95867b251e0fa3d307488fa6f 100644 --- a/alib2algo/src/regexp/glushkov/GlushkovFollow.h +++ b/alib2algo/src/regexp/glushkov/GlushkovFollow.h @@ -82,11 +82,14 @@ ext::set < UnboundedRegExpSymbol < SymbolType > > GlushkovFollow::follow ( const template < class SymbolType > ext::set < regexp::UnboundedRegExpSymbol < SymbolType > > GlushkovFollow::Unbounded < SymbolType >::visit ( const regexp::UnboundedRegExpAlternation < SymbolType > & node, const regexp::UnboundedRegExpSymbol < SymbolType > & symbolptr ) { - for ( const UnboundedRegExpElement < SymbolType > & element : node.getElements ( ) ) - if ( element.template accept < bool, GlushkovPos::Unbounded < SymbolType > > ( symbolptr ) ) - return element.template accept < ext::set < regexp::UnboundedRegExpSymbol < SymbolType > >, GlushkovFollow::Unbounded < SymbolType > > ( symbolptr ); + auto iter = std::find_if ( node.getElements ( ).begin ( ), node.getElements ( ).end ( ), [ & ] ( const UnboundedRegExpElement < SymbolType > & element ) { + return element.template accept < bool, GlushkovPos::Unbounded < SymbolType > > ( symbolptr ); + } ); - throw exception::CommonException ( "GlushkovFollow::Unbounded < SymbolType >::visit(Alt)" ); + if ( iter == node.getElements ( ).end ( ) ) + throw exception::CommonException ( "GlushkovFollow::Unbounded < SymbolType >::visit(Alt)" ); + + return iter->template accept < ext::set < regexp::UnboundedRegExpSymbol < SymbolType > >, GlushkovFollow::Unbounded < SymbolType > > ( symbolptr ); } template < class SymbolType > diff --git a/alib2algo/src/regexp/glushkov/GlushkovPos.h b/alib2algo/src/regexp/glushkov/GlushkovPos.h index 127bc4ed74a504ab6261ce0fd4799a5fb803faf6..d319818af702233f1e466615017fe9b5865a70a0 100644 --- a/alib2algo/src/regexp/glushkov/GlushkovPos.h +++ b/alib2algo/src/regexp/glushkov/GlushkovPos.h @@ -52,20 +52,16 @@ bool GlushkovPos::pos ( const UnboundedRegExpSymbol < SymbolType > & symbol, con template < class SymbolType > bool GlushkovPos::Unbounded < SymbolType >::visit ( const regexp::UnboundedRegExpAlternation < SymbolType > & node, const regexp::UnboundedRegExpSymbol < SymbolType > & symbol ) { - for ( const UnboundedRegExpElement < SymbolType > & element : node.getElements ( ) ) - if ( element.template accept < bool, GlushkovPos::Unbounded < SymbolType > > ( symbol ) ) - return true; - - return false; + return std::any_of ( node.getElements ( ).begin ( ), node.getElements ( ).end ( ), [ & ] ( const UnboundedRegExpElement < SymbolType > & element ) { + return element.template accept < bool, GlushkovPos::Unbounded < SymbolType > > ( symbol ); + } ); } template < class SymbolType > bool GlushkovPos::Unbounded < SymbolType >::visit ( const regexp::UnboundedRegExpConcatenation < SymbolType > & node, const regexp::UnboundedRegExpSymbol < SymbolType > & symbol ) { - for ( const UnboundedRegExpElement < SymbolType > & element : node.getElements ( ) ) - if ( element.template accept < bool, GlushkovPos::Unbounded < SymbolType > > ( symbol ) ) - return true; - - return false; + return std::any_of ( node.getElements ( ).begin ( ), node.getElements ( ).end ( ), [ & ] ( const UnboundedRegExpElement < SymbolType > & element ) { + return element.template accept < bool, GlushkovPos::Unbounded < SymbolType > > ( symbol ); + } ); } template < class SymbolType > diff --git a/alib2algo/src/regexp/properties/RegExpEmpty.h b/alib2algo/src/regexp/properties/RegExpEmpty.h index d10f29783628e171f9c1e47ead869131500e8143..4dc3befb381ec52fa19e4ee25e903f7dc25435c2 100644 --- a/alib2algo/src/regexp/properties/RegExpEmpty.h +++ b/alib2algo/src/regexp/properties/RegExpEmpty.h @@ -127,22 +127,16 @@ bool RegExpEmpty::languageIsEmpty(const regexp::UnboundedRegExp < SymbolType > & template < class SymbolType > bool RegExpEmpty::Unbounded< SymbolType >::visit(const regexp::UnboundedRegExpAlternation < SymbolType > & alternation) { - for(const UnboundedRegExpElement < SymbolType > & element : alternation.getElements()) { - if(! element.template accept < bool, RegExpEmpty::Unbounded < SymbolType > > ( ) ) { - return false; - } - } - return true; + return std::all_of ( alternation.getElements ( ).begin ( ), alternation.getElements ( ).end ( ), [ ] ( const UnboundedRegExpElement < SymbolType > & element ) { + return element.template accept < bool, RegExpEmpty::Unbounded < SymbolType > > ( ); + } ); } template < class SymbolType > bool RegExpEmpty::Unbounded< SymbolType >::visit(const regexp::UnboundedRegExpConcatenation < SymbolType > & concatenation) { - for(const UnboundedRegExpElement < SymbolType > & element : concatenation.getElements()) { - if( element.template accept < bool, RegExpEmpty::Unbounded < SymbolType > > ( ) ) { - return true; - } - } - return false; + return std::any_of ( concatenation.getElements ( ).begin ( ), concatenation.getElements ( ).end ( ), [ ] ( const UnboundedRegExpElement < SymbolType > & element ) { + return element.template accept < bool, RegExpEmpty::Unbounded < SymbolType > > ( ); + } ); } template < class SymbolType > diff --git a/alib2algo/src/regexp/properties/RegExpEpsilon.h b/alib2algo/src/regexp/properties/RegExpEpsilon.h index a5852a74fd6885211bd618faa85b9724ed879cf5..6addca6b3501a856c0922157431d6b55bcacf3ce 100644 --- a/alib2algo/src/regexp/properties/RegExpEpsilon.h +++ b/alib2algo/src/regexp/properties/RegExpEpsilon.h @@ -126,20 +126,16 @@ bool RegExpEpsilon::languageContainsEpsilon(const regexp::UnboundedRegExp < Symb template < class SymbolType > bool RegExpEpsilon::Unbounded < SymbolType >::visit(const regexp::UnboundedRegExpAlternation < SymbolType > & alternation) { - for ( const UnboundedRegExpElement < SymbolType > & element : alternation.getElements ( ) ) - if ( element.template accept < bool, RegExpEpsilon::Unbounded < SymbolType > > ( ) ) - return true; - - return false; + return std::any_of ( alternation.getElements ( ).begin ( ), alternation.getElements ( ).end ( ), [ ] ( const UnboundedRegExpElement < SymbolType > & element ) { + return element.template accept < bool, RegExpEpsilon::Unbounded < SymbolType > > ( ); + } ); } template < class SymbolType > bool RegExpEpsilon::Unbounded < SymbolType >::visit(const regexp::UnboundedRegExpConcatenation < SymbolType > & concatenation) { - for ( const UnboundedRegExpElement < SymbolType > & element : concatenation.getElements ( ) ) - if ( ! element.template accept < bool, RegExpEpsilon::Unbounded < SymbolType > > ( ) ) - return false; - - return true; + return std::all_of ( concatenation.getElements ( ).begin ( ), concatenation.getElements ( ).end ( ), [ ] ( const UnboundedRegExpElement < SymbolType > & element ) { + return element.template accept < bool, RegExpEpsilon::Unbounded < SymbolType > > ( ); + } ); } template < class SymbolType > diff --git a/alib2algo/src/rte/glushkov/GlushkovPos.h b/alib2algo/src/rte/glushkov/GlushkovPos.h index ddfbc8ea96fdc7140e6b765f98f75414dc290be3..ebec88cd4cb985f66d457657794232c2e0e28105 100644 --- a/alib2algo/src/rte/glushkov/GlushkovPos.h +++ b/alib2algo/src/rte/glushkov/GlushkovPos.h @@ -59,11 +59,9 @@ template < class SymbolType > bool GlushkovPos::Formal < SymbolType >::visit ( const rte::FormalRTESymbolAlphabet < SymbolType > & node, const common::ranked_symbol < SymbolType > & symbolF ) { if ( symbolF == node.getSymbol ( ) ) return true; - for ( const rte::FormalRTEElement < SymbolType > & element : node.getElements ( ) ) - if ( element.template accept < bool, GlushkovPos::Formal < SymbolType > > ( symbolF ) ) - return true; - - return false; + return std::any_of ( node.getElements ( ).begin ( ), node.getElements ( ).end ( ), [ & ] ( const rte::FormalRTEElement < SymbolType > & element ) { + return element.template accept < bool, GlushkovPos::Formal < SymbolType > > ( symbolF ); + } ); } template < class SymbolType > diff --git a/alib2xml/src/registry/XmlContainerParserRegistry.cpp b/alib2xml/src/registry/XmlContainerParserRegistry.cpp index 5d069679ada841ff88f6918fd76806c82ead24c4..7a196b6db40fd036a46dd54fb6aff3dbd501e0c4 100644 --- a/alib2xml/src/registry/XmlContainerParserRegistry.cpp +++ b/alib2xml/src/registry/XmlContainerParserRegistry.cpp @@ -53,11 +53,14 @@ std::shared_ptr < abstraction::OperationAbstraction > XmlContainerParserRegistry if ( group == getEntries ( ).end ( ) ) throw exception::CommonException ( "Entry " + container + " not available" ); - for ( const ext::pair < std::string, std::unique_ptr < Entry > > & entry : group->second ) - if ( ext::is_same_type ( type, ext::erase_template_info ( entry.first ) ) ) - return entry.second->getAbstraction ( ); + auto iter = std::find_if ( group->second.begin ( ), group->second.end ( ), [ & ] ( const ext::pair < std::string, std::unique_ptr < Entry > > & entry ) { + return ext::is_same_type ( type, ext::erase_template_info ( entry.first ) ); + } ); + + if ( iter == group->second.end ( ) ) + throw exception::CommonException ( "Entry for " + container + " parametrized with " + type + " not available." ); - throw exception::CommonException ( "Entry for " + container + " parametrized with " + type + " not available." ); + return iter->second->getAbstraction ( ); } ext::set < std::string > XmlContainerParserRegistry::listOverloads ( const std::string & container ) {