Skip to content

Commit

Permalink
Support comparing tuples in localized_compare
Browse files Browse the repository at this point in the history
  • Loading branch information
jbytheway committed May 5, 2020
1 parent 8591e64 commit 5a3880c
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/translations.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <string>
#include <vector>
#include <type_traits>
#include <utility>

#include "optional.h"

Expand Down Expand Up @@ -263,13 +264,31 @@ struct localized_comparator {
return ( *this )( l.second, r.second );
}

template<typename Head, typename... Tail>
bool operator()( const std::tuple<Head, Tail...> &l,
const std::tuple<Head, Tail...> &r ) const {
if( ( *this )( std::get<0>( l ), std::get<0>( r ) ) ) {
return true;
}
if( ( *this )( std::get<0>( r ), std::get<0>( l ) ) ) {
return false;
}
constexpr std::make_index_sequence<sizeof...( Tail )> Ints{};
return ( *this )( tie_tail( l, Ints ), tie_tail( r, Ints ) );
}

template<typename T>
bool operator()( const T &l, const T &r ) const {
return l < r;
}

bool operator()( const std::string &, const std::string & ) const;
bool operator()( const std::wstring &, const std::wstring & ) const;

template<typename Head, typename... Tail, size_t... Ints>
auto tie_tail( const std::tuple<Head, Tail...> &t, std::index_sequence<Ints...> ) const {
return std::tie( std::get < Ints + 1 > ( t )... );
}
};

constexpr localized_comparator localized_compare{};
Expand Down

0 comments on commit 5a3880c

Please sign in to comment.