W jaki sposób można użyć metody enable_if dla wzajemnie wykluczających się szablonów funkcji innych niż członkowie?

Próbuję napisać szablony funkcji operatora innych niż:

#include <utility>

template < typename T, unsigned L >
class MyType;

template < typename T, typename U, unsigned L >
auto  operator ==( MyType<T,L> const &l, MyType<U,L> const &r )
 -> decltype( std::declval<T>() == std::declval<U>() )
{ /*...*/ }

Ale kiedy próbuję sobie z tym poradzićl ir mają różne długości:

template < typename T, unsigned Lt, typename U, unsigned Lu, class Enable = typename std::enable_if<(Lt < Lu)>::type >
auto  operator ==( MyType<T,Lt> const &l, MyType<U,Lu> const &r )
 -> decltype( std::declval<T>() == std::declval<U>() )
{ /*...*/ }

template < typename T, unsigned Lt, typename U, unsigned Lu, class Enable = typename std::enable_if<(Lt > Lu)>::type >
auto  operator ==( MyType<T,Lt> const &l, MyType<U,Lu> const &r )
 -> decltype( std::declval<T>() == std::declval<U>() )
{ /*...*/ }

Dostaję błędy niejednoznaczności. Próbowałem czegoś takiego:

template < typename T, unsigned Lt, typename U, unsigned Lu, bool B = (Lt < Lu), class Enable = typename std::enable_if<B>::type >
auto  operator ==( MyType<T,Lt> const &l, MyType<U,Lu> const &r )
 -> decltype( std::declval<T>() == std::declval<U>() )
{ /*...*/ }

template < typename T, unsigned Lt, typename U, unsigned Lu, bool B = (Lt > Lu), class Enable = typename std::enable_if<B>::type >
auto  operator ==( MyType<T,Lt> const &l, MyType<U,Lu> const &r )
 -> decltype( std::declval<T>() == std::declval<U>() )
{ /*...*/ }

które przeczytałem (tutaj na S.O.), aby rozwiązać takie problemy jak szablony funkcji członkowskich. (Czasami respondenci zmienili funkcję członka na szablon funkcji członka, aby to umożliwić.) Ale błędy nie zmieniają się dla mnie. Czy muszę przejść na stawianieenable_if w typ powrotu?

Och, wyrażenie typu zwracanego powinno wykluczać tego operatora, gdy nie można porównać dwóch typów elementów. Czy to zadziała? Czy jest to zgodne z ustawieniemenable_if tam też?

questionAnswers(1)

yourAnswerToTheQuestion