Skip to content
Snippets Groups Projects
Commit c739a234 authored by Jan Trávníček's avatar Jan Trávníček
Browse files

move linear_set to namespace ext

parent e85a5799
No related branches found
No related tags found
No related merge requests found
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
   
#include "compare.hpp" #include "compare.hpp"
   
namespace std { namespace ext {
   
template < class T, class Compare = std::less<T>, class Alloc = std::allocator<T> > template < class T, class Compare = std::less<T>, class Alloc = std::allocator<T> >
class linear_set { class linear_set {
...@@ -249,8 +249,9 @@ public: ...@@ -249,8 +249,9 @@ public:
} }
   
void swap (linear_set& x) { void swap (linear_set& x) {
std::swap ( m_data, x.m_data ); using std::swap;
std::swap ( m_comp, x.m_comp ); swap ( m_data, x.m_data );
swap ( m_comp, x.m_comp );
} }
   
iterator upper_bound (const T& val) { iterator upper_bound (const T& val) {
...@@ -292,12 +293,12 @@ public: ...@@ -292,12 +293,12 @@ public:
}; };
   
template <class T, class Compare, class Alloc> 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 ); x.swap ( y );
} }
   
template< class T, class ... Ts > 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 << "{"; out << "{";
   
bool first = true; bool first = true;
...@@ -311,13 +312,9 @@ std::ostream& operator<<(std::ostream& out, const linear_set<T, Ts ...>& list) { ...@@ -311,13 +312,9 @@ std::ostream& operator<<(std::ostream& out, const linear_set<T, Ts ...>& list) {
return out; return out;
} }
   
} /* namespace std */
namespace ext {
template<class T, class ... Ts> template<class T, class ... Ts>
struct compare<std::linear_set<T, Ts ...>> { struct compare<ext::linear_set<T, Ts ...>> {
int operator()(const std::linear_set<T, Ts ...>& first, const std::linear_set<T, Ts ...>& second) const { 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;
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 ...>> { ...@@ -331,16 +328,12 @@ struct compare<std::linear_set<T, Ts ...>> {
}; };
   
template < class T, class ... 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; std::stringstream ss;
ss << value; ss << value;
return ss.str(); return ss.str();
} }
   
} /* namespace ext */
namespace std {
template <class Iterator> template <class Iterator>
class linear_set_move_iterator { class linear_set_move_iterator {
Iterator current; Iterator current;
...@@ -462,6 +455,6 @@ linear_set < T > operator +( const linear_set < T > & first, const linear_set < ...@@ -462,6 +455,6 @@ linear_set < T > operator +( const linear_set < T > & first, const linear_set <
return res; return res;
} }
   
} /* namespace std */ } /* namespace ext */
   
#endif /* __LINEAR_SET_HPP_ */ #endif /* __LINEAR_SET_HPP_ */
...@@ -13,8 +13,8 @@ void LinearSetTest::tearDown() { ...@@ -13,8 +13,8 @@ void LinearSetTest::tearDown() {
   
void LinearSetTest::test1() { void LinearSetTest::test1() {
std::vector < int > data = { 1, 4, 3 }; std::vector < int > data = { 1, 4, 3 };
std::linear_set < int > test_set_1; ext::linear_set < int > test_set_1;
std::linear_set < int > test_set_2 ( data.begin ( ), data.end ( ) ); ext::linear_set < int > test_set_2 ( data.begin ( ), data.end ( ) );
   
CPPUNIT_ASSERT ( test_set_1.size ( ) == 0 ); CPPUNIT_ASSERT ( test_set_1.size ( ) == 0 );
CPPUNIT_ASSERT ( test_set_1.empty ( ) ); CPPUNIT_ASSERT ( test_set_1.empty ( ) );
...@@ -28,7 +28,7 @@ void LinearSetTest::test1() { ...@@ -28,7 +28,7 @@ void LinearSetTest::test1() {
} }
test_set_1.clear ( ); test_set_1.clear ( );
CPPUNIT_ASSERT ( test_set_1.empty ( ) ); 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 ( ) ); CPPUNIT_ASSERT ( iter == test_set_1.begin ( ) );
   
iter = test_set_1.insert ( data [1] ).first; iter = test_set_1.insert ( data [1] ).first;
...@@ -55,11 +55,11 @@ void LinearSetTest::test1() { ...@@ -55,11 +55,11 @@ void LinearSetTest::test1() {
} }
   
void LinearSetTest::test2() { void LinearSetTest::test2() {
std::linear_set<int> first = {1}; ext::linear_set<int> first = {1};
std::linear_set<int> second = {1, 2, 3}; ext::linear_set<int> second = {1, 2, 3};
   
std::linear_set<int> firstMinusSecond; ext::linear_set<int> firstMinusSecond;
std::linear_set<int> secondMinusFirst; ext::linear_set<int> secondMinusFirst;
   
std::set_difference (first.begin(), first.end(), second.begin(), second.end(), std::inserter(firstMinusSecond, firstMinusSecond.end())); 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())); std::set_difference (second.begin(), second.end(), first.begin(), first.end(), std::inserter(secondMinusFirst, secondMinusFirst.end()));
...@@ -72,11 +72,11 @@ void LinearSetTest::test3() { ...@@ -72,11 +72,11 @@ void LinearSetTest::test3() {
int moves; int moves;
int copies; int copies;
   
std::linear_set<LinearSetTest::Moveable> set; ext::linear_set<LinearSetTest::Moveable> set;
set.insert ( LinearSetTest::Moveable(moves, copies) ); 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)); set2.insert(std::move(moveable));
} }
   
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment