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

static compare functor 3

parent b1a70e08
No related branches found
No related tags found
No related merge requests found
Showing
with 22 additions and 23 deletions
...@@ -87,7 +87,7 @@ struct compare<double> { ...@@ -87,7 +87,7 @@ struct compare<double> {
template<class T> template<class T>
struct compare<T*> { struct compare<T*> {
int operator()( T * const & first, T * const & second) const { int operator()( T * const & first, T * const & second) const {
compare<typename std::decay < T >::type > comp; static compare<typename std::decay < T >::type > comp;
return comp(*first, *second); return comp(*first, *second);
} }
}; };
...@@ -95,7 +95,7 @@ struct compare<T*> { ...@@ -95,7 +95,7 @@ struct compare<T*> {
template<class T> template<class T>
struct compare<T&> { struct compare<T&> {
int operator()( const T & first, const T & second) const { int operator()( const T & first, const T & second) const {
compare<typename std::decay < T >::type > comp; static compare<typename std::decay < T >::type > comp;
return comp(first, second); return comp(first, second);
} }
}; };
......
...@@ -34,7 +34,7 @@ struct compare < deque < T, Ts ... > > { ...@@ -34,7 +34,7 @@ struct compare < deque < T, Ts ... > > {
   
if ( first.size ( ) > second.size ( ) ) return 1; if ( first.size ( ) > second.size ( ) ) return 1;
   
compare < typename std::decay < T >::type > comp; static compare < typename std::decay < T >::type > comp;
   
for ( auto iterF = first.begin ( ), iterS = second.begin ( ); iterF != first.end ( ); ++iterF, ++iterS ) { for ( auto iterF = first.begin ( ), iterS = second.begin ( ); iterF != first.end ( ); ++iterF, ++iterS ) {
int res = comp ( * iterF, * iterS ); int res = comp ( * iterF, * iterS );
......
...@@ -31,7 +31,7 @@ struct compare<forward_list<T, Ts ... >> { ...@@ -31,7 +31,7 @@ struct compare<forward_list<T, Ts ... >> {
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;
   
compare<typename std::decay < T >::type > comp; static compare<typename std::decay < T >::type > comp;
for(auto iterF = first.begin(), iterS = second.begin(); iterF != first.end(); ++iterF, ++iterS) { for(auto iterF = first.begin(), iterS = second.begin(); iterF != first.end(); ++iterF, ++iterS) {
int res = comp(*iterF, *iterS); int res = comp(*iterF, *iterS);
if(res != 0) return res; if(res != 0) return res;
......
...@@ -514,7 +514,7 @@ public: ...@@ -514,7 +514,7 @@ public:
// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
   
int compare ( const forward_tree & other ) const { int compare ( const forward_tree & other ) const {
std::compare < typename std::decay < T >::type > comp; static std::compare < typename std::decay < T >::type > comp;
auto iterF = this->prefix_begin ( ); auto iterF = this->prefix_begin ( );
auto iterS = other.prefix_begin ( ); auto iterS = other.prefix_begin ( );
   
......
...@@ -309,7 +309,7 @@ struct compare<linear_set<T, Ts ...>> { ...@@ -309,7 +309,7 @@ struct compare<linear_set<T, Ts ...>> {
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;
   
compare<typename std::decay < T >::type > comp; static compare<typename std::decay < T >::type > comp;
for(auto iterF = first.begin(), iterS = second.begin(); iterF != first.end(); ++iterF, ++iterS) { for(auto iterF = first.begin(), iterS = second.begin(); iterF != first.end(); ++iterF, ++iterS) {
int res = comp(*iterF, *iterS); int res = comp(*iterF, *iterS);
if(res != 0) return res; if(res != 0) return res;
......
...@@ -31,7 +31,7 @@ struct compare<list<T, Ts ... >> { ...@@ -31,7 +31,7 @@ struct compare<list<T, Ts ... >> {
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;
   
compare<typename std::decay < T >::type > comp; static compare<typename std::decay < T >::type > comp;
for(auto iterF = first.begin(), iterS = second.begin(); iterF != first.end(); ++iterF, ++iterS) { for(auto iterF = first.begin(), iterS = second.begin(); iterF != first.end(); ++iterF, ++iterS) {
int res = comp(*iterF, *iterS); int res = comp(*iterF, *iterS);
if(res != 0) return res; if(res != 0) return res;
......
...@@ -31,7 +31,7 @@ struct compare<map<T, R, Ts ...>> { ...@@ -31,7 +31,7 @@ struct compare<map<T, R, Ts ...>> {
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;
   
compare<std::pair<typename std::decay < T >::type, typename std::decay < R >::type >> comp; static compare<std::pair<typename std::decay < T >::type, typename std::decay < R >::type >> comp;
for(auto iterF = first.begin(), iterS = second.begin(); iterF != first.end(); ++iterF, ++iterS) { for(auto iterF = first.begin(), iterS = second.begin(); iterF != first.end(); ++iterF, ++iterS) {
int res = comp(*iterF, *iterS); int res = comp(*iterF, *iterS);
if(res != 0) return res; if(res != 0) return res;
......
...@@ -368,7 +368,7 @@ struct compare < cow_shared_ptr < T > > { ...@@ -368,7 +368,7 @@ struct compare < cow_shared_ptr < T > > {
   
if ( !second ) return 1; if ( !second ) return 1;
   
compare < typename std::decay < T >::type > comp; static compare < typename std::decay < T >::type > comp;
return comp ( * first, * second ); return comp ( * first, * second );
} }
   
...@@ -383,7 +383,7 @@ struct compare < shared_ptr < T > > { ...@@ -383,7 +383,7 @@ struct compare < shared_ptr < T > > {
   
if ( !second ) return 1; if ( !second ) return 1;
   
compare < typename std::decay < T >::type > comp; static compare < typename std::decay < T >::type > comp;
return comp ( * first, * second ); return comp ( * first, * second );
} }
   
...@@ -398,7 +398,7 @@ struct compare < unique_ptr < T > > { ...@@ -398,7 +398,7 @@ struct compare < unique_ptr < T > > {
   
if ( !second ) return 1; if ( !second ) return 1;
   
compare < typename std::decay < T >::type > comp; static compare < typename std::decay < T >::type > comp;
return comp ( * first, * second ); return comp ( * first, * second );
} }
   
...@@ -413,7 +413,7 @@ struct compare < smart_ptr < T > > { ...@@ -413,7 +413,7 @@ struct compare < smart_ptr < T > > {
   
if ( !second ) return 1; if ( !second ) return 1;
   
compare < typename std::decay < T >::type > comp; static compare < typename std::decay < T >::type > comp;
return comp ( * first, * second ); return comp ( * first, * second );
} }
   
......
...@@ -19,8 +19,8 @@ std::ostream& operator<<(std::ostream& out, const std::pair<T, R>& pair) { ...@@ -19,8 +19,8 @@ std::ostream& operator<<(std::ostream& out, const std::pair<T, R>& pair) {
template<class T, class R> template<class T, class R>
struct compare<pair<T, R>> { struct compare<pair<T, R>> {
int operator()(const pair<T, R>& first, const pair<T, R>& second) const { int operator()(const pair<T, R>& first, const pair<T, R>& second) const {
compare<typename std::decay < T >::type > compT; static compare<typename std::decay < T >::type > compT;
compare<typename std::decay < R >::type > compR; static compare<typename std::decay < R >::type > compR;
   
int res = compT(first.first, second.first); int res = compT(first.first, second.first);
if(res == 0) res = compR(first.second, second.second); if(res == 0) res = compR(first.second, second.second);
......
...@@ -31,7 +31,7 @@ struct compare<set<T, Ts ...>> { ...@@ -31,7 +31,7 @@ struct compare<set<T, Ts ...>> {
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;
   
compare<typename std::decay < T >::type > comp; static compare<typename std::decay < T >::type > comp;
for(auto iterF = first.begin(), iterS = second.begin(); iterF != first.end(); ++iterF, ++iterS) { for(auto iterF = first.begin(), iterS = second.begin(); iterF != first.end(); ++iterF, ++iterS) {
int res = comp(*iterF, *iterS); int res = comp(*iterF, *iterS);
if(res != 0) return res; if(res != 0) return res;
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
* Author: Jan Travnicek * Author: Jan Travnicek
*/ */
   
#include <compare>
#include <string> #include <string>
#include <sstream> #include <sstream>
   
......
...@@ -551,7 +551,7 @@ public: ...@@ -551,7 +551,7 @@ public:
// ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- // ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
   
int compare ( const tree & other ) const { int compare ( const tree & other ) const {
std::compare < typename std::decay < T >::type > comp; static std::compare < typename std::decay < T >::type > comp;
auto iterF = this->prefix_begin ( ); auto iterF = this->prefix_begin ( );
auto iterS = other.prefix_begin ( ); auto iterS = other.prefix_begin ( );
   
......
...@@ -228,7 +228,7 @@ public: ...@@ -228,7 +228,7 @@ public:
auto first = std::tie ( this->getData ( ), this->getChildren ( ) ); auto first = std::tie ( this->getData ( ), this->getChildren ( ) );
auto second = std::tie ( other.getData ( ), other.getChildren ( ) ); auto second = std::tie ( other.getData ( ), other.getChildren ( ) );
   
std::compare < decltype ( first ) > comp; static std::compare < decltype ( first ) > comp;
   
return comp ( first, second ); return comp ( first, second );
} }
......
...@@ -46,7 +46,7 @@ struct compareTupleHelper { ...@@ -46,7 +46,7 @@ struct compareTupleHelper {
   
if ( res != 0 ) return res; if ( res != 0 ) return res;
   
compare < typename std::decay < typename tuple_element < I, Tuple >::type >::type > comp; static compare < typename std::decay < typename tuple_element < I, Tuple >::type >::type > comp;
return comp ( std::get < I > ( t1 ), std::get < I > ( t2 ) ); return comp ( std::get < I > ( t1 ), std::get < I > ( t2 ) );
} }
   
...@@ -55,7 +55,7 @@ struct compareTupleHelper { ...@@ -55,7 +55,7 @@ struct compareTupleHelper {
template < class Tuple > template < class Tuple >
struct compareTupleHelper < 0, Tuple > { struct compareTupleHelper < 0, Tuple > {
static int compHelp ( const Tuple & t1, const Tuple & t2 ) { static int compHelp ( const Tuple & t1, const Tuple & t2 ) {
compare < typename std::decay < typename tuple_element < 0, Tuple >::type >::type > comp; static compare < typename std::decay < typename tuple_element < 0, Tuple >::type >::type > comp;
return comp ( std::get < 0 > ( t1 ), std::get < 0 > ( t2 ) ); return comp ( std::get < 0 > ( t1 ), std::get < 0 > ( t2 ) );
} }
   
......
...@@ -31,7 +31,7 @@ struct compare<unordered_map<T, R, Ts ...>> { ...@@ -31,7 +31,7 @@ struct compare<unordered_map<T, R, Ts ...>> {
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;
   
compare<typename std::decay < R >::type > comp; static compare<typename std::decay < R >::type > comp;
for(auto iter = first.begin(); iter != first.end(); ++iter) { for(auto iter = first.begin(); iter != first.end(); ++iter) {
auto search = second.find(iter->first); auto search = second.find(iter->first);
if(search == second.end()) return -1; if(search == second.end()) return -1;
......
...@@ -101,7 +101,7 @@ struct variant_helper<F, Ts...> { ...@@ -101,7 +101,7 @@ struct variant_helper<F, Ts...> {
   
inline static int compareHelper(type_id_hash_code this_t, const void * this_v, type_id_hash_code other_t, const void * other_v) { inline static int compareHelper(type_id_hash_code this_t, const void * this_v, type_id_hash_code other_t, const void * other_v) {
if (this_t == typeid(F).hash_code() && other_t == typeid(F).hash_code()) { if (this_t == typeid(F).hash_code() && other_t == typeid(F).hash_code()) {
compare<typename std::decay < F >::type > comp; static compare<typename std::decay < F >::type > comp;
return comp( *(reinterpret_cast<const F*>(this_v)), *(reinterpret_cast<const F*>(other_v))); return comp( *(reinterpret_cast<const F*>(this_v)), *(reinterpret_cast<const F*>(other_v)));
} else } else
return variant_helper<Ts...>::compareHelper(this_t, this_v, other_t, other_v); return variant_helper<Ts...>::compareHelper(this_t, this_v, other_t, other_v);
......
...@@ -31,7 +31,7 @@ struct compare<vector<T, Ts ...>> { ...@@ -31,7 +31,7 @@ struct compare<vector<T, Ts ...>> {
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;
   
compare<typename std::decay < T >::type > comp; static compare<typename std::decay < T >::type > comp;
for(auto iterF = first.begin(), iterS = second.begin(); iterF != first.end(); ++iterF, ++iterS) { for(auto iterF = first.begin(), iterS = second.begin(); iterF != first.end(); ++iterF, ++iterS) {
int res = comp(*iterF, *iterS); int res = comp(*iterF, *iterS);
if(res != 0) return res; if(res != 0) return res;
......
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