Skip to content

Commit

Permalink
(compatibility) enable clang compilation
Browse files Browse the repository at this point in the history
- replaced fallback operator implementation based on
  C-style varargs with operators triggered by SFINAE inclusion/exclusion

- tested with clang 18 and gcc 12

issue #41
  • Loading branch information
ppete committed Dec 11, 2024
1 parent 055eb52 commit 5fe4215
Showing 1 changed file with 43 additions and 6 deletions.
49 changes: 43 additions & 6 deletions include/clippy/clippy-eval.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2454,6 +2454,19 @@ namespace json_logic
return compareSeq(deref(lv), deref(rv), std::move(pred));
}

// convenience template that only returns a type when the types mismatch
template <class U, class V, class ResultType>
struct MismatchedTypes
{
using type = ResultType;
};

template <class T, class ResultType>
struct MismatchedTypes<T,T,ResultType>
{
// using type // triggers SFINAE exclusion
};


//
// the calc operator implementations
Expand All @@ -2466,11 +2479,17 @@ namespace json_logic
{
using EqualityOperator::result_type;

result_type operator()(...) const { return false; } // type mismatch
template <class U, class V>
auto
operator()(const U&, const V&) const
-> typename MismatchedTypes<U,V,result_type>::type // type mismatch
{
return false;
}

template <class T>
result_type
operator()(const T& lhs, const T& rhs) const
auto
operator()(const T& lhs, const T& rhs) const -> result_type
{
return lhs == rhs;
}
Expand All @@ -2481,7 +2500,13 @@ namespace json_logic
{
using EqualityOperator::result_type;

result_type operator()(...) const { return true; } // type mismatch
template <class U, class V>
auto
operator()(const U&, const V&) const
-> typename MismatchedTypes<U,V,result_type>::type // type mismatch
{
return true;
}

template <class T>
result_type
Expand All @@ -2496,7 +2521,13 @@ namespace json_logic
{
using StrictEqualityOperator::result_type;

result_type operator()(...) const { return false; } // type mismatch
template <class U, class V>
auto
operator()(const U&, const V&) const
-> typename MismatchedTypes<U,V,result_type>::type // type mismatch
{
return false;
}

template <class T>
result_type
Expand All @@ -2511,7 +2542,13 @@ namespace json_logic
{
using StrictEqualityOperator::result_type;

result_type operator()(...) const { return true; } // type mismatch
template <class U, class V>
auto
operator()(const U&, const V&) const
-> typename MismatchedTypes<U,V,result_type>::type // type mismatch
{
return true;
}

template <class T>
result_type
Expand Down

0 comments on commit 5fe4215

Please sign in to comment.