From c739a2340f8d1f99e2fa73fcd95106258f6c9e14 Mon Sep 17 00:00:00 2001 From: Jan Travnicek <Jan.Travnicek@fit.cvut.cz> Date: Mon, 7 Aug 2017 15:36:20 +0200 Subject: [PATCH] move linear_set to namespace ext --- alib2std/src/extensions/linear_set.hpp | 27 +++++++------------ .../test-src/extensions/LinearSetTest.cpp | 20 +++++++------- 2 files changed, 20 insertions(+), 27 deletions(-) diff --git a/alib2std/src/extensions/linear_set.hpp b/alib2std/src/extensions/linear_set.hpp index 3194615804..c29b3a88b9 100644 --- a/alib2std/src/extensions/linear_set.hpp +++ b/alib2std/src/extensions/linear_set.hpp @@ -16,7 +16,7 @@ #include "compare.hpp" -namespace std { +namespace ext { template < class T, class Compare = std::less<T>, class Alloc = std::allocator<T> > class linear_set { @@ -249,8 +249,9 @@ public: } void swap (linear_set& x) { - std::swap ( m_data, x.m_data ); - std::swap ( m_comp, x.m_comp ); + using std::swap; + swap ( m_data, x.m_data ); + swap ( m_comp, x.m_comp ); } iterator upper_bound (const T& val) { @@ -292,12 +293,12 @@ public: }; template <class T, class Compare, class Alloc> -void swap ( linear_set < T, Compare, Alloc > & x, linear_set < T, Compare, Alloc > & y) { +void swap ( ext::linear_set < T, Compare, Alloc > & x, ext::linear_set < T, Compare, Alloc > & y) { x.swap ( y ); } template< class T, class ... Ts > -std::ostream& operator<<(std::ostream& out, const linear_set<T, Ts ...>& list) { +std::ostream& operator<<(std::ostream& out, const ext::linear_set<T, Ts ...>& list) { out << "{"; bool first = true; @@ -311,13 +312,9 @@ std::ostream& operator<<(std::ostream& out, const linear_set<T, Ts ...>& list) { return out; } -} /* namespace std */ - -namespace ext { - template<class T, class ... Ts> -struct compare<std::linear_set<T, Ts ...>> { - int operator()(const std::linear_set<T, Ts ...>& first, const std::linear_set<T, Ts ...>& second) const { +struct compare<ext::linear_set<T, Ts ...>> { + int operator()(const ext::linear_set<T, Ts ...>& first, const ext::linear_set<T, Ts ...>& second) const { if(first.size() < second.size()) return -1; if(first.size() > second.size()) return 1; @@ -331,16 +328,12 @@ struct compare<std::linear_set<T, Ts ...>> { }; template < class T, class ... Ts > -std::string to_string ( const std::linear_set < T, Ts ... > & value ) { +std::string to_string ( const ext::linear_set < T, Ts ... > & value ) { std::stringstream ss; ss << value; return ss.str(); } -} /* namespace ext */ - -namespace std { - template <class Iterator> class linear_set_move_iterator { Iterator current; @@ -462,6 +455,6 @@ linear_set < T > operator +( const linear_set < T > & first, const linear_set < return res; } -} /* namespace std */ +} /* namespace ext */ #endif /* __LINEAR_SET_HPP_ */ diff --git a/alib2std/test-src/extensions/LinearSetTest.cpp b/alib2std/test-src/extensions/LinearSetTest.cpp index 37edd92b35..e101a7c7ee 100644 --- a/alib2std/test-src/extensions/LinearSetTest.cpp +++ b/alib2std/test-src/extensions/LinearSetTest.cpp @@ -13,8 +13,8 @@ void LinearSetTest::tearDown() { void LinearSetTest::test1() { std::vector < int > data = { 1, 4, 3 }; - std::linear_set < int > test_set_1; - std::linear_set < int > test_set_2 ( data.begin ( ), data.end ( ) ); + ext::linear_set < int > test_set_1; + ext::linear_set < int > test_set_2 ( data.begin ( ), data.end ( ) ); CPPUNIT_ASSERT ( test_set_1.size ( ) == 0 ); CPPUNIT_ASSERT ( test_set_1.empty ( ) ); @@ -28,7 +28,7 @@ void LinearSetTest::test1() { } test_set_1.clear ( ); CPPUNIT_ASSERT ( test_set_1.empty ( ) ); - std::linear_set < int >::iterator iter = test_set_1.insert ( data [0] ).first; + ext::linear_set < int >::iterator iter = test_set_1.insert ( data [0] ).first; CPPUNIT_ASSERT ( iter == test_set_1.begin ( ) ); iter = test_set_1.insert ( data [1] ).first; @@ -55,11 +55,11 @@ void LinearSetTest::test1() { } void LinearSetTest::test2() { - std::linear_set<int> first = {1}; - std::linear_set<int> second = {1, 2, 3}; + ext::linear_set<int> first = {1}; + ext::linear_set<int> second = {1, 2, 3}; - std::linear_set<int> firstMinusSecond; - std::linear_set<int> secondMinusFirst; + ext::linear_set<int> firstMinusSecond; + ext::linear_set<int> secondMinusFirst; std::set_difference (first.begin(), first.end(), second.begin(), second.end(), std::inserter(firstMinusSecond, firstMinusSecond.end())); std::set_difference (second.begin(), second.end(), first.begin(), first.end(), std::inserter(secondMinusFirst, secondMinusFirst.end())); @@ -72,11 +72,11 @@ void LinearSetTest::test3() { int moves; int copies; - std::linear_set<LinearSetTest::Moveable> set; + ext::linear_set<LinearSetTest::Moveable> set; set.insert ( LinearSetTest::Moveable(moves, copies) ); - std::linear_set<LinearSetTest::Moveable> set2; + ext::linear_set<LinearSetTest::Moveable> set2; - for(Moveable moveable : std::make_moveable_set(set)) { + for(Moveable moveable : ext::make_moveable_set(set)) { set2.insert(std::move(moveable)); } -- GitLab