diff --git a/alib2algo/src/automaton/determinize/common/NFACommon.cpp b/alib2algo/src/automaton/determinize/common/NFACommon.cpp index 52d945fdf2255a8378a2c93c140f0b2514782dbf..6f371a466d7eb37d7bd0a21c9bed2aa7ce44f374 100644 --- a/alib2algo/src/automaton/determinize/common/NFACommon.cpp +++ b/alib2algo/src/automaton/determinize/common/NFACommon.cpp @@ -16,10 +16,10 @@ namespace automaton { namespace determinize { -automaton::State createDFAState(const std::set<automaton::State>& nfaStates) { +automaton::State createDFAState(std::set<automaton::State> nfaStates) { std::set<label::Label> labelSet; - for(const automaton::State& state : nfaStates) { - labelSet.insert(state.getName()); + for(automaton::State state : std::make_moveable_set(nfaStates)) { + labelSet.insert(std::move(state.getName())); } return automaton::State(label::Label(label::LabelSetLabel(std::move(labelSet)))); } diff --git a/alib2algo/src/automaton/determinize/common/NFACommon.h b/alib2algo/src/automaton/determinize/common/NFACommon.h index 2265efdf84cab10999f5441fdeba3781d5a471db..b24e34397252d9fd352cc874dbd856442e4e8a4e 100644 --- a/alib2algo/src/automaton/determinize/common/NFACommon.h +++ b/alib2algo/src/automaton/determinize/common/NFACommon.h @@ -22,7 +22,7 @@ namespace determinize { * @param originalStates set of states from nondeterministic fsm which represents state of deterministic fsm * @return state of deterministic fsm */ -automaton::State createDFAState(const std::set<automaton::State>& nfaStates); +automaton::State createDFAState(std::set<automaton::State> nfaStates); /** * Finds states from nondeterministic fsm to which at least one state from given set of states have transition diff --git a/alib2std/src/extensions/set.hpp b/alib2std/src/extensions/set.hpp index 96904208e3d7f166c614db7b96ac5ee656647253..21803471306cf24303d2fcb5652fd29989ef0d26 100644 --- a/alib2std/src/extensions/set.hpp +++ b/alib2std/src/extensions/set.hpp @@ -129,6 +129,26 @@ set_move_iterator<Iterator> make_set_move_iterator (Iterator it) { return set_move_iterator<Iterator>(it); } +template<class T> +class moveable_set { + set<T>& theSet; +public: + moveable_set(set<T>& param) : theSet(param) {} + + set_move_iterator<typename set<T>::iterator> begin() { + return make_set_move_iterator(theSet.begin()); + } + + set_move_iterator<typename set<T>::iterator> end() { + return make_set_move_iterator(theSet.end()); + } +}; + +template<class T> +moveable_set<T> make_moveable_set (std::set<T>& set) { + return moveable_set<T>(set); +} + } /* namespace std */ #endif /* __SET_HPP_ */ diff --git a/alib2std/test-src/extensions/SetTest.cpp b/alib2std/test-src/extensions/SetTest.cpp index f5c4cbcc78b15670f8e52e28b88e5a433ff80f80..712b4cd16afb6bdc66402cdcf8392928b1439e60 100644 --- a/alib2std/test-src/extensions/SetTest.cpp +++ b/alib2std/test-src/extensions/SetTest.cpp @@ -42,3 +42,42 @@ void SetTest::test2() { CPPUNIT_ASSERT_EQUAL(firstMinusSecond.size(), 0ul); CPPUNIT_ASSERT_EQUAL(secondMinusFirst.size(), 2ul); } + +class Moveable { + int& moves; + int& copies; + +public: + Moveable(int& moves, int& copies) : moves(moves), copies(copies) { + moves = 0; + copies = 0; + } + + Moveable(const Moveable& src) : moves(src.moves), copies(src.copies) { + copies++; + } + + Moveable(Moveable&& src) : moves(src.moves), copies(src.copies) { + moves++; + } + + bool operator<(const Moveable&) const { + return false; + } +}; + +void SetTest::test3() { + int moves; + int copies; + + std::set<Moveable> set = {Moveable(moves, copies)}; + std::set<Moveable> set2; + + for(Moveable moveable : std::make_moveable_set(set)) { + set2.insert(std::move(moveable)); + } + + CPPUNIT_ASSERT(copies == 0); + CPPUNIT_ASSERT(copies == 2); +} + diff --git a/alib2std/test-src/extensions/SetTest.h b/alib2std/test-src/extensions/SetTest.h index bdad1fd2988f248ff105faace57e20eceedab609..ce6f31b5ee5f0f9cfd1747dd6d7fd42c36c4d821 100644 --- a/alib2std/test-src/extensions/SetTest.h +++ b/alib2std/test-src/extensions/SetTest.h @@ -16,6 +16,7 @@ public: void test1(); void test2(); + void test3(); }; #endif // SET_TEST_H_